-
Notifications
You must be signed in to change notification settings - Fork 73
feat: OpenTelemetry standard attributes #4456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
bcee5f4
deprecate onboarding-enabler zutil, move to apiml-utility
0e0b568
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
5243473
Merge remote-tracking branch 'origin' into reboot/feat/otel-standard
4fbb002
initial commit
1acb61c
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
2d03079
wip add calculated attributes
976bb8b
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
46fb08b
wip testing
7d12592
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
1fa20d2
compile issue
06206ef
add defaults
d9d2541
otel test wip
d0e1967
test works
9fa1332
test data is empty
245a277
attempts to have acceptance tests working
a5e5b46
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
a65086e
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle 014845a
InMemoryMetricReader for tests
richard-salac c42575e
rename test, update structure
07054ca
add unit tests
f6dfe77
wip
92f6300
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
c342fc4
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
94c9370
fix for acceptance test
753c7c1
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
f4c4416
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle 1015c38
unit test
1e2b2fc
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle a8be34c
complete functional test
86094cb
remove standard attribute from test
8dd9c79
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle 49520e1
attempt to fix otel settings start.sh
68680c3
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
a667103
add unit test
ba4e739
fix merge issue
f80fba5
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle c7c98ba
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle ed9c5c3
Merge branch 'v3.x.x' into reboot/feat/otel-standard
richard-salac ca9d625
pr review 1
05b870d
use attributes, add exporter settings
80874a4
fix for blank otel properties in start.sh
5c70cf5
add zos attributes
0a4a818
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
1991a26
add comment
c3a45be
wip pr review
4e4a639
fix tests
4461124
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
905a440
remove debug
b4a28f7
pr review
d398ec4
refactor to use nonzos resource provider
ea0ce0b
fix resource provider order
richard-salac 34baf94
fix resource provider order
richard-salac 19c17d5
use zos profile
829b142
remove job id
d6f3d06
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle 628ccef
cleanup config
richard-salac de78efa
handle missing zos symbols
37401eb
Merge branch 'reboot/feat/otel-standard' of https://github.com/zowe/a…
ae3fb11
fix test
02bda92
add apiml prefix for service.name
839bee1
read os.version from jvm properties
richard-salac f6d3d20
Merge remote-tracking branch 'origin/v3.x.x' into reboot/feat/otel-st…
75959c5
fix unit test
9723718
fix merge
599afe7
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle bbc60c0
chore: OpenTelemetry integration test validating resource attributes …
richard-salac 8b960c4
Merge branch 'v3.x.x' into reboot/feat/otel-standard
richard-salac 66eca45
Merge branch 'v3.x.x' into reboot/feat/otel-standard
richard-salac 42a9a94
Merge branch 'v3.x.x' into reboot/feat/otel-standard
richard-salac 2195540
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle 7931a1f
add tests for deployment environment name
richard-salac 1082797
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle 798672e
otel it readme update
richard-salac eeaa8d4
Merge branch 'v3.x.x' into reboot/feat/otel-standard
pablocarle d05495f
fix org.zowe.apiml.product.opentelemetry.ApimlZosOpenTelemetryResourc…
richard-salac c683ef0
minor fixes in readme
c6cbec2
update otel dockers
richard-salac 5f9daa4
solve sonar issues
43db4bb
Merge branch 'reboot/feat/otel-standard' of https://github.com/zowe/a…
95dfc80
Merge branch 'v3.x.x' into reboot/feat/otel-standard
richard-salac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...n/java/org/zowe/apiml/product/opentelemetry/ApimlNonZosOpenTelemetryResourceProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.product.opentelemetry; | ||
|
|
||
| import io.opentelemetry.api.common.Attributes; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| @ConditionalOnMissingBean(ApimlZosOpenTelemetryResourceProvider.class) | ||
| @Component | ||
| public class ApimlNonZosOpenTelemetryResourceProvider extends ApimlOpenTelemetryResourceProvider { | ||
|
|
||
| @Override | ||
| protected @Nonnull Attributes internalCalculateAttributes() { | ||
| return Attributes.empty(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String generateServiceName() { | ||
| var systemName = StringUtils.isBlank(apimlId) ? hostname : apimlId; | ||
| return "apiml:" + systemName + ":" + port; | ||
| } | ||
|
|
||
| } |
95 changes: 95 additions & 0 deletions
95
...rc/main/java/org/zowe/apiml/product/opentelemetry/ApimlOpenTelemetryResourceProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.product.opentelemetry; | ||
|
|
||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| @Slf4j | ||
| public abstract class ApimlOpenTelemetryResourceProvider implements ResourceProvider { | ||
|
|
||
| public static final String OS_VERSION = "os.version"; | ||
|
|
||
| @Value("${otel.resource.attributes.service.namespace:#{null}}") | ||
| private String serviceNamespace; | ||
|
|
||
| @Value("${apiml.service.hostname:localhost}") | ||
| protected String hostname; | ||
|
|
||
| @Value("${apiml.service.port:10010}") | ||
| protected int port; | ||
|
|
||
| @Value("${otel.resource.attributes.service.name:#{null}}") | ||
| private String serviceName; | ||
|
|
||
| @Value("${apiml.service.apimlId:#{null}}") | ||
| protected String apimlId; | ||
|
|
||
| public @Nonnull Attributes calculateAttributes() { | ||
| var attributesBuilder = Attributes.builder(); | ||
|
|
||
| if (StringUtils.isBlank(serviceNamespace)) { | ||
| log.debug("service.namespace is not provided in configuration"); | ||
| } | ||
|
|
||
| if (StringUtils.isBlank(serviceName)) { | ||
| var generatedServiceName = generateServiceName(); | ||
| attributesBuilder.put("service.name", generatedServiceName); | ||
| log.debug("service.name not provided in configuration, using generated default {}", generatedServiceName); | ||
| } | ||
|
|
||
| var instanceId = generateInstanceId(); | ||
| attributesBuilder.put(ZosOpenTelemetryAttributes.OTEL_ZOS_INSTANCE_ID, instanceId); | ||
| log.debug("using generated service.instance.id {}", instanceId); | ||
|
|
||
| // io.opentelemetry.instrumentation.resources.OsResource resolves the version but uses it only to populate os.description | ||
| // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/16211 | ||
| attributesBuilder.put(OS_VERSION, System.getProperty(OS_VERSION)); | ||
|
|
||
| attributesBuilder.putAll(internalCalculateAttributes()); | ||
| return attributesBuilder.build(); | ||
| } | ||
|
|
||
| protected abstract @Nonnull Attributes internalCalculateAttributes(); | ||
|
|
||
| @Override | ||
| public Resource createResource(@Nonnull ConfigProperties config) { | ||
| var attributesBuilder = Attributes.builder(); | ||
|
|
||
| attributesBuilder.putAll(calculateAttributes()); | ||
| return Resource.create(attributesBuilder.build()); | ||
| } | ||
|
|
||
| private String generateInstanceId() { | ||
| return String.format("%s:gateway:%d", hostname, port); | ||
| } | ||
|
|
||
| protected abstract String generateServiceName(); | ||
|
|
||
| @Override | ||
| public int order() { | ||
| /* To run after | ||
| io.opentelemetry.instrumentation.resources.JarServiceNameDetector | ||
| but before | ||
| io.opentelemetry.sdk.autoconfigure.EnvironmentResourceProvider | ||
| io.opentelemetry.sdk.extension.incubator.resources.ServiceInstanceIdResourceProvider | ||
| */ | ||
| return 10000; | ||
| } | ||
|
|
||
| } | ||
115 changes: 115 additions & 0 deletions
115
...main/java/org/zowe/apiml/product/opentelemetry/ApimlZosOpenTelemetryResourceProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.product.opentelemetry; | ||
|
|
||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.common.AttributesBuilder; | ||
| import jakarta.annotation.PostConstruct; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Profile; | ||
| import org.springframework.stereotype.Component; | ||
| import org.zowe.apiml.product.zos.ZosSystemInformation; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import static org.zowe.apiml.product.zos.ZosSystemInformation.ZOS_ENVIRON; | ||
| import static org.zowe.apiml.product.zos.ZosSystemInformation.ZOS_JOB_NAME; | ||
| import static org.zowe.apiml.product.zos.ZosSystemInformation.ZOS_SMF_ID; | ||
| import static org.zowe.apiml.product.zos.ZosSystemInformation.ZOS_SYSNAME; | ||
| import static org.zowe.apiml.product.zos.ZosSystemInformation.ZOS_SYSPLEX; | ||
| import static org.zowe.apiml.product.zos.ZosSystemInformation.ZOS_USER_ID; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| @Profile("zos") | ||
| @Slf4j | ||
| public class ApimlZosOpenTelemetryResourceProvider extends ApimlOpenTelemetryResourceProvider { | ||
|
|
||
| private final ZosSystemInformation zosSystemInformation; | ||
|
|
||
| @Value("${otel.resource.attributes.deployment.environment.name:#{null}}") | ||
| private String environmentName; | ||
|
pablocarle marked this conversation as resolved.
|
||
|
|
||
| @Value("${otel.resource.attributes.zos.sysplex.name:#{null}}") | ||
| private String sysplexName; | ||
|
|
||
| @Value("${otel.resource.attributes.mainframe.lpar.name:#{null}}") | ||
| private String lparName; | ||
|
|
||
| @Value("${otel.resource.attributes.zos.smf.id:#{null}}") | ||
| private String smfId; | ||
|
|
||
| @PostConstruct | ||
| void afterPropertiesSet() { | ||
| log.debug("Using ZOS OpenTelemetry resource provider"); | ||
| } | ||
|
|
||
| private void attribute(AttributesBuilder attributesBuilder, @Nonnull String openTelemetryAttribute, String zosAttribute) { | ||
| var zosAttributes = zosSystemInformation.get(); | ||
| var zosValue = zosAttributes.get(zosAttribute); | ||
| if (zosValue != null && StringUtils.isNotBlank(zosValue.toString())) { | ||
| log.debug(openTelemetryAttribute + " not provided in configuration, using z/OS obtained {}", zosValue); | ||
| attributesBuilder.put(openTelemetryAttribute, zosValue.toString()); | ||
| } else { | ||
| log.debug(openTelemetryAttribute + " not provided in configuration. Could not determine it from system"); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("null") | ||
| @Override | ||
| @Nonnull | ||
| protected Attributes internalCalculateAttributes() { | ||
| var attributesBuilder = Attributes.builder(); | ||
|
|
||
| var zosAttributes = zosSystemInformation.get(); | ||
|
|
||
| if (StringUtils.isBlank(environmentName)) { | ||
| attribute(attributesBuilder, "deployment.environment.name", ZOS_ENVIRON); | ||
| } | ||
|
|
||
| if (StringUtils.isBlank(sysplexName)) { | ||
| attribute(attributesBuilder, "zos.sysplex.name", ZOS_SYSPLEX); | ||
| } | ||
|
|
||
| if (StringUtils.isBlank(lparName)) { | ||
| attribute(attributesBuilder, "mainframe.lpar.name", ZOS_SYSNAME); | ||
| } | ||
|
|
||
| if (StringUtils.isBlank(smfId)) { | ||
| attribute(attributesBuilder, "zos.smf.id", ZOS_SMF_ID); | ||
| } | ||
|
pablocarle marked this conversation as resolved.
|
||
|
|
||
| Optional.ofNullable(zosAttributes.get(ZOS_JOB_NAME)) | ||
| .map(String::valueOf) | ||
| .filter(StringUtils::isNotBlank) | ||
| .ifPresent(zosJobName -> attributesBuilder.put(ZosOpenTelemetryAttributes.OTEL_ZOS_JOBNAME, zosJobName)); | ||
|
|
||
| Optional.ofNullable(zosAttributes.get(ZOS_USER_ID)) | ||
| .map(String::valueOf) | ||
| .filter(StringUtils::isNotBlank) | ||
| .ifPresent(zosUserId -> attributesBuilder.put(ZosOpenTelemetryAttributes.OTEL_ZOS_USERID, zosUserId)); | ||
|
|
||
| return attributesBuilder.build(); | ||
|
pablocarle marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| protected String generateServiceName() { | ||
| var zosAttributes = zosSystemInformation.get(); | ||
| var systemName = StringUtils.isBlank(apimlId) ? zosAttributes.get(ZOS_SYSPLEX) : apimlId; | ||
| return "apiml:" + systemName + ":" + port; | ||
| } | ||
|
|
||
| } | ||
22 changes: 22 additions & 0 deletions
22
...common/src/main/java/org/zowe/apiml/product/opentelemetry/ZosOpenTelemetryAttributes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.product.opentelemetry; | ||
|
|
||
| /** | ||
| * Set of attributes set by API ML | ||
| */ | ||
| public class ZosOpenTelemetryAttributes { | ||
|
Check warning on line 16 in apiml-common/src/main/java/org/zowe/apiml/product/opentelemetry/ZosOpenTelemetryAttributes.java
|
||
|
|
||
| public static final String OTEL_ZOS_JOBNAME = "process.zos.jobname"; | ||
| public static final String OTEL_ZOS_USERID = "process.zos.userid"; | ||
| public static final String OTEL_ZOS_INSTANCE_ID = "service.instance.id"; | ||
|
|
||
| } | ||
54 changes: 54 additions & 0 deletions
54
...va/org/zowe/apiml/product/opentelemetry/ApimlNonZosOpenTelemetryResourceProviderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * This program and the accompanying materials are made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
| * https://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| * | ||
| * Copyright Contributors to the Zowe Project. | ||
| */ | ||
|
|
||
| package org.zowe.apiml.product.opentelemetry; | ||
|
|
||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.test.util.ReflectionTestUtils; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class ApimlNonZosOpenTelemetryResourceProviderTest { | ||
|
|
||
| private ApimlNonZosOpenTelemetryResourceProvider resourceProvider; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| this.resourceProvider = new ApimlNonZosOpenTelemetryResourceProvider(); | ||
| ReflectionTestUtils.setField(resourceProvider, "hostname", "localhost"); | ||
| ReflectionTestUtils.setField(resourceProvider, "port", 10010); | ||
| } | ||
|
|
||
| @Test | ||
| void testCalculateAttributes() { | ||
| var result = resourceProvider.calculateAttributes(); | ||
| assertFalse(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testCreateResource() { | ||
| var result = resourceProvider.createResource(mock(ConfigProperties.class)); | ||
| assertFalse(result.getAttributes().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testServiceName() { | ||
| var result = resourceProvider.generateServiceName(); | ||
| assertEquals("apiml:localhost:10010", result); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.