feat(detectors): add EC2 resource detection via IMDSv2 - #23
Merged
Conversation
Add native EC2 instance metadata and tag detection to the go-agent, enabled via LAST9_CLOUD_RESOURCE_DETECTION=aws. Uses IMDSv2 with graceful fallback — zero overhead on non-EC2 environments.
- Reorder EC2Detector struct fields to fix fieldalignment (govet) - Run gofmt on test file to fix formatting
muktaa
self-requested a review
March 21, 2026 09:29
muktaa
approved these changes
Mar 21, 2026
karthikeyangs9
added a commit
that referenced
this pull request
Mar 23, 2026
This reverts commit 48a497e.
2 tasks
prathamesh-sonpatki
added a commit
that referenced
this pull request
Mar 23, 2026
Revert: feat(detectors): add EC2 resource detection via IMDSv2 (#23)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
LAST9_CLOUD_RESOURCE_DETECTION=awsenv var to opt-in (zero cost when unset)resource.Detectorindetectors/aws/— no AWS SDK dependencyMotivation
The go-agent's
createResource()has no cloud resource detection. Users running on EC2 miss valuable attributes (cloud.region,host.id, instance tags) that are critical for filtering and grouping telemetry in Last9.Previously, the only workaround was a shell script enriching
OTEL_RESOURCE_ATTRIBUTESbefore the binary starts. This PR makes it native to the agent.What it does
When
LAST9_CLOUD_RESOURCE_DETECTION=awsis set, the agent'screateResource()adds an EC2 detector that:/latest/api/tokenwith TTL header)us-east-1a→us-east-1)/latest/meta-data/tags/instance/(requires "Allow tags in instance metadata" enabled on the EC2 instance)Resource attributes produced
cloud.provider=awscloud.regioncloud.availability_zonehost.idhost.typehost.nameec2.tag.<Key>Graceful degradation
/latest/meta-data/tags/instancereturns 404 → tags skipped, metadata still collectedFiles changed
config/config.goCloudResourceDetectionfield, readsLAST9_CLOUD_RESOURCE_DETECTIONagent.goresource.WithDetectors()when config is"aws"detectors/aws/ec2.godetectors/aws/ec2_test.goUsage
export LAST9_CLOUD_RESOURCE_DETECTION=awsNo code changes required —
agent.Start()picks it up automatically.Test plan
TestDetect_FullMetadataAndTags— all metadata + 3 tags returned correctlyTestDetect_NoTags— tags endpoint missing, core metadata still worksTestDetect_IMDSUnreachable— non-EC2 env returns empty resource, no errorTestDetect_PartialMetadata— only instance-id available, no region/AZTestDetect_TokenValidation— IMDSv2 token sent on all metadata requestsgo test ./... -race)go vet ./...clean