From b35725b34e8c3ff193cc1cfd9d3e7ff0e199afa0 Mon Sep 17 00:00:00 2001 From: Shivam Jaiswal Date: Tue, 8 Mar 2022 13:39:30 +0530 Subject: [PATCH 1/2] telemetry sdk name changed --- .../detectors/common/LMCommonResource.java | 22 +++++++++++++++++++ .../common/LMCommonResourceProvider.java | 13 +++++++++++ ...try.sdk.autoconfigure.spi.ResourceProvider | 3 ++- .../common/LMCommonResourceProviderTest.java | 21 ++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java create mode 100644 otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProvider.java create mode 100644 otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java diff --git a/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java b/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java new file mode 100644 index 0000000..19fd48a --- /dev/null +++ b/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java @@ -0,0 +1,22 @@ +package com.logicmonitor.resource.detectors.common; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; + +public class LMCommonResource { + private static final Resource INSTANCE = buildResource(); + + public static Resource get() { + return INSTANCE; + } + + static Resource buildResource() { + AttributesBuilder attrBuilders = Attributes.builder(); + String telemetrySdkName = "lm-opentelemetry"; + attrBuilders.put(ResourceAttributes.TELEMETRY_SDK_NAME, telemetrySdkName); + + return Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL); + } +} diff --git a/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProvider.java b/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProvider.java new file mode 100644 index 0000000..e2dbc69 --- /dev/null +++ b/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProvider.java @@ -0,0 +1,13 @@ +package com.logicmonitor.resource.detectors.common; + +// import com.logicmonitor.resource.detectors.aws.ec2.LMEc2Resource; +import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; +import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; +import io.opentelemetry.sdk.resources.Resource; + +public class LMCommonResourceProvider implements ResourceProvider { + @Override + public Resource createResource(ConfigProperties config) { + return LMCommonResource.get(); + } +} diff --git a/otel-resource/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider b/otel-resource/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider index 2e9cde8..6587e72 100644 --- a/otel-resource/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider +++ b/otel-resource/src/main/resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider @@ -1 +1,2 @@ -com.logicmonitor.resource.detectors.aws.ec2.LMEc2ResourceProvider \ No newline at end of file +com.logicmonitor.resource.detectors.aws.ec2.LMEc2ResourceProvider +com.logicmonitor.resource.detectors.common.LMCommonResourceProvider \ No newline at end of file diff --git a/otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java b/otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java new file mode 100644 index 0000000..4cb5140 --- /dev/null +++ b/otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java @@ -0,0 +1,21 @@ +package com.logicmonitor.resource.detectors.common; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; +import org.junit.jupiter.api.Test; + +public class LMCommonResourceProviderTest { + @Test + public void whenProvidedValidCommonResourceThenReturnResourceWithTelemetrySDKName() { + AttributesBuilder attrBuilders = Attributes.builder(); + String telemetrySdkName = "lm-opentelemetry"; + attrBuilders.put(ResourceAttributes.TELEMETRY_SDK_NAME, telemetrySdkName); + Resource resources = Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL); + Resource lmResource = LMCommonResource.buildResource(); + assertEquals(resources, lmResource); + } +} From 96ffeb36208906547cb25c61b24871fe85c315b3 Mon Sep 17 00:00:00 2001 From: Shivam Jaiswal Date: Tue, 8 Mar 2022 14:52:21 +0530 Subject: [PATCH 2/2] optimised --- .../resource/detectors/common/LMCommonResource.java | 3 +-- .../detectors/common/LMCommonResourceProviderTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java b/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java index 19fd48a..fea6f21 100644 --- a/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java +++ b/otel-resource/src/main/java/com/logicmonitor/resource/detectors/common/LMCommonResource.java @@ -14,8 +14,7 @@ public static Resource get() { static Resource buildResource() { AttributesBuilder attrBuilders = Attributes.builder(); - String telemetrySdkName = "lm-opentelemetry"; - attrBuilders.put(ResourceAttributes.TELEMETRY_SDK_NAME, telemetrySdkName); + attrBuilders.put(ResourceAttributes.TELEMETRY_SDK_NAME, "lm-opentelemetry"); return Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL); } diff --git a/otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java b/otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java index 4cb5140..402353f 100644 --- a/otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java +++ b/otel-resource/src/test/java/com/logicmonitor/resource/detectors/common/LMCommonResourceProviderTest.java @@ -12,8 +12,7 @@ public class LMCommonResourceProviderTest { @Test public void whenProvidedValidCommonResourceThenReturnResourceWithTelemetrySDKName() { AttributesBuilder attrBuilders = Attributes.builder(); - String telemetrySdkName = "lm-opentelemetry"; - attrBuilders.put(ResourceAttributes.TELEMETRY_SDK_NAME, telemetrySdkName); + attrBuilders.put(ResourceAttributes.TELEMETRY_SDK_NAME, "lm-opentelemetry"); Resource resources = Resource.create(attrBuilders.build(), ResourceAttributes.SCHEMA_URL); Resource lmResource = LMCommonResource.buildResource(); assertEquals(resources, lmResource);