use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class SdkLogEmitterTest method logBuilder_maxAttributeLength.
@Test
void logBuilder_maxAttributeLength() {
int maxLength = 25;
AtomicReference<LogData> seenLog = new AtomicReference<>();
SdkLogEmitterProvider logEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(seenLog::set).setLogLimits(() -> LogLimits.builder().setMaxAttributeValueLength(maxLength).build()).build();
LogBuilder logBuilder = logEmitterProvider.get("test").logBuilder();
String strVal = StringUtils.padLeft("", maxLength);
String tooLongStrVal = strVal + strVal;
logBuilder.setAttributes(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()).emit();
Attributes attributes = seenLog.get().getAttributes();
assertThat(attributes).containsEntry("string", strVal).containsEntry("boolean", true).containsEntry("long", 1L).containsEntry("double", 1.0).containsEntry("stringArray", strVal, strVal).containsEntry("booleanArray", true, false).containsEntry("longArray", 1L, 2L).containsEntry("doubleArray", 1.0, 2.0);
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class ResourceTest method create.
@Test
void create() {
Attributes attributes = Attributes.of(stringKey("a"), "1", stringKey("b"), "2");
Resource resource = Resource.create(attributes);
assertThat(resource.getAttributes()).isNotNull();
assertThat(resource.getAttributes().size()).isEqualTo(2);
assertThat(resource.getAttributes()).isEqualTo(attributes);
Resource resource1 = Resource.create(Attributes.empty());
assertThat(resource1.getAttributes()).isNotNull();
assertThat(resource1.getAttributes().isEmpty()).isTrue();
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class ResourceTest method setUp.
@BeforeEach
void setUp() {
Attributes attributes1 = Attributes.of(stringKey("a"), "1", stringKey("b"), "2");
Attributes attribute2 = Attributes.of(stringKey("a"), "1", stringKey("b"), "3", stringKey("c"), "4");
resource1 = Resource.create(attributes1);
resource2 = Resource.create(attribute2);
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class ResourceTest method testMergeResources_Resource1_Null.
@Test
void testMergeResources_Resource1_Null() {
Attributes expectedAttributes = Attributes.of(stringKey("a"), "1", stringKey("b"), "3", stringKey("c"), "4");
Resource resource = Resource.empty().merge(null).merge(resource2);
assertThat(resource.getAttributes()).isEqualTo(expectedAttributes);
}
use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.
the class ResourceTest method shouldBuilderHelperMethodsBuildResource.
@Test
void shouldBuilderHelperMethodsBuildResource() {
// given
ResourceBuilder builder = Resource.getDefault().toBuilder();
Attributes sourceAttributes = Attributes.of(stringKey("hello"), "world");
Resource source = Resource.create(sourceAttributes);
Attributes sourceAttributes2 = Attributes.of(stringKey("OpenTelemetry"), "Java");
// when
Resource resource = builder.put("long", 42L).put("double", Math.E).put("boolean", true).put("string", "abc").put("long array", 1L, 2L, 3L).put("double array", Math.E, Math.PI).put("boolean array", true, false).put("string array", "first", "second").put(longKey("long key"), 4242L).put(longKey("int in disguise"), 21).putAll(source).putAll(sourceAttributes2).build();
// then
Attributes attributes = resource.getAttributes();
assertThat(attributes.get(longKey("long"))).isEqualTo(42L);
assertThat(attributes.get(doubleKey("double"))).isEqualTo(Math.E);
assertThat(attributes.get(booleanKey("boolean"))).isEqualTo(true);
assertThat(attributes.get(stringKey("string"))).isEqualTo("abc");
assertThat(attributes.get(longArrayKey("long array"))).isEqualTo(Arrays.asList(1L, 2L, 3L));
assertThat(attributes.get(doubleArrayKey("double array"))).isEqualTo(Arrays.asList(Math.E, Math.PI));
assertThat(attributes.get(booleanArrayKey("boolean array"))).isEqualTo(Arrays.asList(true, false));
assertThat(attributes.get(stringArrayKey("string array"))).isEqualTo(Arrays.asList("first", "second"));
assertThat(attributes.get(longKey("long key"))).isEqualTo(4242L);
assertThat(attributes.get(longKey("int in disguise"))).isEqualTo(21);
assertThat(attributes.get(stringKey("hello"))).isEqualTo("world");
assertThat(attributes.get(stringKey("OpenTelemetry"))).isEqualTo("Java");
}
Aggregations