Skip to content

feat(serviceevents): resolve aws.local.environment for SE/DI in the SDK to align with CloudWatch agent - #1417

Draft
jj22ee wants to merge 2 commits into
aws-observability:mainfrom
jj22ee:sdk-deployment-env-pr
Draft

feat(serviceevents): resolve aws.local.environment for SE/DI in the SDK to align with CloudWatch agent#1417
jj22ee wants to merge 2 commits into
aws-observability:mainfrom
jj22ee:sdk-deployment-env-pr

Conversation

@jj22ee

@jj22ee jj22ee commented Jul 8, 2026

Copy link
Copy Markdown
Member

ServiceEvents and Dynamic Instrumentation need aws.local.environment, which today only the CloudWatch agent sets. This adds an SDK-side resolver that computes the same value the agent's awsapplicationsignals resolver would, from the OTel Resource, with no dependency on the agent process:

  • EnvironmentResolver: mirror the agent's precedence — explicit deployment.environment[.name] -> eks/k8s:/ -> ecs: -> ec2:/ec2:default -> generic:default (never empty, matching the agent's generic resolver off-platform).
  • Ec2AutoScalingGroupFetcher: read the ASG name from IMDS instance tags (the stock OTel EC2 detector omits it), invoked lazily only on the EC2 branch and memoized process-wide.
  • DI: resolve aws.local.environment for the instrumentation-config lookup key from the autoconfigured resource.

Unit tests included for the resolver, ASG fetcher, and DI config.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…n with CloudWatch agent

ServiceEvents and Dynamic Instrumentation need aws.local.environment, which today
only the CloudWatch agent sets. This adds an SDK-side resolver that computes the
same value the agent's awsapplicationsignals resolver would, from the OTel Resource,
with no dependency on the agent process:

- EnvironmentResolver: mirror the agent's precedence — explicit
  deployment.environment[.name] -> eks/k8s:<cluster>/<namespace> -> ecs:<cluster> ->
  ec2:<asg>/ec2:default -> generic:default (never empty, matching the agent's
  generic resolver off-platform).
- Ec2AutoScalingGroupFetcher: read the ASG name from IMDS instance tags (the stock
  OTel EC2 detector omits it), invoked lazily only on the EC2 branch and memoized
  process-wide.
- DI: resolve aws.local.environment for the instrumentation-config lookup key from the
  autoconfigured resource.

Unit tests included for the resolver, ASG fetcher, and DI config.
@jj22ee
jj22ee force-pushed the sdk-deployment-env-pr branch from 1efdb82 to 4b0bbfc Compare July 8, 2026 23:20
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 80.00000% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.90%. Comparing base (09e6487) to head (4b0bbfc).
⚠️ Report is 597 commits behind head on main.

Files with missing lines Patch % Lines
...ent/providers/environment/EnvironmentResolver.java 82.19% 5 Missing and 8 partials ⚠️
...viders/environment/Ec2AutoScalingGroupFetcher.java 83.78% 3 Missing and 3 partials ⚠️
...mentation/config/DynamicInstrumentationConfig.java 50.00% 0 Missing and 2 partials ⚠️
...on/serviceevents/ServiceEventsInstrumentation.java 0.00% 2 Missing ⚠️
...Instrumentation/DynamicInstrumentationManager.java 75.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@              Coverage Diff              @@
##               main    #1417       +/-   ##
=============================================
- Coverage     85.71%   58.90%   -26.82%     
- Complexity       19     1654     +1635     
=============================================
  Files             3      140      +137     
  Lines            49     9803     +9754     
  Branches          5     1412     +1407     
=============================================
+ Hits             42     5774     +5732     
- Misses            3     3488     +3485     
- Partials          4      541      +537     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…s own behavior

The resolveLocalEnvironment javadoc said it returns "" on a non-AWS / undetected host,
but the method returns generic:default (matching the CloudWatch agent's generic resolver,
which never leaves Environment empty). Stale text from before the non-AWS fix; the
class-level javadoc was already correct. Doc-only change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants