Skip to content

otellambda: allow custom attributes#7556

Merged
dmathieu merged 14 commits into
open-telemetry:mainfrom
matbrito:main
Jul 23, 2025
Merged

otellambda: allow custom attributes#7556
dmathieu merged 14 commits into
open-telemetry:mainfrom
matbrito:main

Conversation

@matbrito
Copy link
Copy Markdown
Contributor

@matbrito matbrito commented Jul 7, 2025

This PR introduces a new feature to the AWS Lambda OpenTelemetry Go instrumentation, allowing users to attach custom attributes to spans based on the Lambda event payload. This enhancement provides greater flexibility for enriching traces with application-specific context.

Changes

New Option: WithTraceAttributeFn

  • Added a new option function, WithTraceAttributeFn, which accepts an TraceAttributeFn (a function that can extracts attributes from the event JSON).
  • Updated the internal config struct to include a TraceAttributeFn field.
  • The default extractor is a no-op, returning no attributes.

Instrumentation Logic Update

  • During span creation, the configured TraceAttributeFn is called with the event payload.
  • Any attributes returned by this function are appended to the span’s attributes.

Unit Tests

  • Added a new test, TestWrapHandlerTracingWithTraceAttributeFn, to verify that custom attributes extracted from the event are correctly attached to the span.
  • The test uses a mock and asserts that the expected custom attribute is present in the span.

@matbrito matbrito requested a review from a team as a code owner July 7, 2025 14:00
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Jul 7, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@matbrito
Copy link
Copy Markdown
Contributor Author

matbrito commented Jul 7, 2025

#7557

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.7%. Comparing base (2e2c53f) to head (5216c8d).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7556   +/-   ##
=====================================
  Coverage   78.7%   78.7%           
=====================================
  Files        186     186           
  Lines      14807   14816    +9     
=====================================
+ Hits       11656   11665    +9     
  Misses      2803    2803           
  Partials     348     348           
Files with missing lines Coverage Δ
.../github.com/aws/aws-lambda-go/otellambda/config.go 100.0% <100.0%> (ø)
.../github.com/aws/aws-lambda-go/otellambda/lambda.go 89.6% <100.0%> (+0.5%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread CHANGELOG.md Outdated
@MrAlias
Copy link
Copy Markdown
Contributor

MrAlias commented Jul 8, 2025

Thanks for your interest in the project. Please provide a complete enhancement issue in #7557 prior to proposing a change here. Design and motivation can be discussed there.

@MrAlias MrAlias closed this Jul 8, 2025
@dmathieu dmathieu reopened this Jul 15, 2025
@matbrito matbrito requested a review from dmathieu July 19, 2025 02:04
@dmathieu
Copy link
Copy Markdown
Member

@akats7 what do you think of this, as code owner?

@akats7
Copy link
Copy Markdown
Contributor

akats7 commented Jul 21, 2025

This is a good update, definitely seems valuable

@matbrito matbrito requested a review from akats7 July 23, 2025 01:06
@dmathieu dmathieu merged commit 26088c5 into open-telemetry:main Jul 23, 2025
28 checks passed
@MrAlias MrAlias added this to the v1.38.0 milestone Aug 20, 2025
@MrAlias MrAlias mentioned this pull request Aug 29, 2025
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.

4 participants