use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class ZipkinSpanExporterTest method generateSpan_AlreadyHasHttpStatusInfo.
@Test
void generateSpan_AlreadyHasHttpStatusInfo() {
Attributes attributeMap = Attributes.of(SemanticAttributes.HTTP_STATUS_CODE, 404L, stringKey("error"), "A user provided error");
SpanData data = buildStandardSpan().setAttributes(attributeMap).setKind(SpanKind.CLIENT).setStatus(StatusData.error()).setTotalAttributeCount(2).build();
assertThat(exporter.generateSpan(data)).isEqualTo(buildZipkinSpan(Span.Kind.CLIENT).toBuilder().clearTags().putTag(SemanticAttributes.HTTP_STATUS_CODE.getKey(), "404").putTag(ZipkinSpanExporter.OTEL_STATUS_CODE, "ERROR").putTag("error", "A user provided error").build());
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class ProcessResourceTest method windows.
@Test
@SetSystemProperty(key = "os.name", value = "Windows 10")
void windows() {
Resource resource = ProcessResource.buildResource();
assertThat(resource.getSchemaUrl()).isEqualTo(ResourceAttributes.SCHEMA_URL);
Attributes attributes = resource.getAttributes();
assertThat(attributes.get(ResourceAttributes.PROCESS_PID)).isGreaterThan(1);
assertThat(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH)).contains("java").endsWith(".exe");
assertThat(attributes.get(ResourceAttributes.PROCESS_COMMAND_LINE)).contains(attributes.get(ResourceAttributes.PROCESS_EXECUTABLE_PATH));
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class ProcessRuntimeResourceTest method shouldCreateRuntimeAttributes.
@Test
void shouldCreateRuntimeAttributes() {
// when
Resource resource = ProcessRuntimeResource.buildResource();
Attributes attributes = resource.getAttributes();
// then
assertThat(resource.getSchemaUrl()).isEqualTo(ResourceAttributes.SCHEMA_URL);
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_NAME)).isNotBlank();
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_VERSION)).isNotBlank();
assertThat(attributes.get(ResourceAttributes.PROCESS_RUNTIME_DESCRIPTION)).isNotBlank();
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class SdkSpanTest method attributeLength.
@Test
void attributeLength() {
int maxLength = 25;
SdkSpan span = createTestSpan(SpanLimits.builder().setMaxAttributeValueLength(maxLength).build());
try {
String strVal = IntStream.range(0, maxLength).mapToObj(i -> "a").collect(joining());
String tooLongStrVal = strVal + strVal;
Attributes attributes = Attributes.builder().put("string", tooLongStrVal).put("boolean", true).put("long", 1L).put("double", 1.0).put(stringArrayKey("stringArray"), Arrays.asList(strVal, tooLongStrVal)).put(booleanArrayKey("booleanArray"), Arrays.asList(true, false)).put(longArrayKey("longArray"), Arrays.asList(1L, 2L)).put(doubleArrayKey("doubleArray"), Arrays.asList(1.0, 2.0)).build();
span.setAllAttributes(attributes);
attributes = span.toSpanData().getAttributes();
assertThat(attributes.get(stringKey("string"))).isEqualTo(strVal);
assertThat(attributes.get(booleanKey("boolean"))).isEqualTo(true);
assertThat(attributes.get(longKey("long"))).isEqualTo(1L);
assertThat(attributes.get(doubleKey("double"))).isEqualTo(1.0);
assertThat(attributes.get(stringArrayKey("stringArray"))).isEqualTo(Arrays.asList(strVal, strVal));
assertThat(attributes.get(booleanArrayKey("booleanArray"))).isEqualTo(Arrays.asList(true, false));
assertThat(attributes.get(longArrayKey("longArray"))).isEqualTo(Arrays.asList(1L, 2L));
assertThat(attributes.get(doubleArrayKey("doubleArray"))).isEqualTo(Arrays.asList(1.0, 2.0));
} finally {
span.end();
}
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class SdkSpanTest method setAllAttributes_mergesAttributes.
@Test
void setAllAttributes_mergesAttributes() {
SdkSpan span = createTestRootSpan();
Attributes attributes = Attributes.builder().put("StringKey", "StringVal").put("LongKey", 1000L).put("DoubleKey", 10.0).put("BooleanKey", false).build();
try {
span.setAttribute("StringKey", "OtherStringVal").setAttribute("ExistingStringKey", "ExistingStringVal").setAttribute("LongKey", 2000L).setAllAttributes(attributes);
} finally {
span.end();
}
SpanData spanData = span.toSpanData();
assertThat(spanData.getAttributes().size()).isEqualTo(5);
assertThat(spanData.getAttributes().get(stringKey("StringKey"))).isNotNull().isEqualTo("StringVal");
assertThat(spanData.getAttributes().get(stringKey("ExistingStringKey"))).isNotNull().isEqualTo("ExistingStringVal");
assertThat(spanData.getAttributes().get(longKey("LongKey"))).isNotNull().isEqualTo(1000L);
assertThat(spanData.getAttributes().get(doubleKey("DoubleKey"))).isNotNull().isEqualTo(10.0);
assertThat(spanData.getAttributes().get(booleanKey("BooleanKey"))).isNotNull().isEqualTo(false);
}
Aggregations