Skip to content
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

NH-69217 sw.transaction attribute on otlp traces, metrics #307

Merged
merged 7 commits into from
Feb 7, 2024

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Feb 6, 2024

Updates Sampler to add sw.transaction attribute to spans, if experimental ("OTLP export") flag is set.

Dumbs down OTLPMetricsSpanProcessor to match sw.transaction attribute in OTLP metrics.

We can only customize transaction value for spans with the env var SW_APM_TRANSACTION_NAME or AWS_LAMBDA_FUNCTION_NAME, not with the SDK (see Confluence). For now, the latter env var we assume is always there. Backups in case not present are the span's name, else "unknown_service" like Resource in the SDK.

Tests from a mocked lambda environment and requested route with a 3s sleep as follows.

SW_APM_TRANSACTION_NAME: my-cool-txn and AWS_LAMBDA_FUNCTION_NAME: flask-mock-lambda:

AWS_LAMBDA_FUNCTION_NAME: flask-mock-lambda:

Please let me know what you think.

@tammy-baylis-swi tammy-baylis-swi changed the title NH-69217 sw.transaction attribute NH-69217 sw.transaction attribute on otlp traces, metrics Feb 7, 2024
@@ -415,6 +419,35 @@ def add_tracestate_capture_to_attributes_dict(
)
return attributes_dict

def calculate_otlp_transaction_name(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new sampler function duplicates what's in the otlp metrics processor. If this should be split it out into a shared place, I'm not sure where to put it. Maybe a top-level util like W3CTransformer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes good point, it would be nice to have it shared, although W3C... is very much an HTTP header concern while transaction naming is our SWO-specific concept, so I wouldn't put it there.

There is the top-level apm_txnname_manager, and some other transaction name classes under trace/ that might fit the bill. But you may want to just defer the refactoring until you've had a chance to investigate the idea of subclassing the OTel exporter in order to support custom SDK naming for lambda (which can definitely be a future iteration).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I couldn't remember that exact piece. Made a ticket for subclassing: https://swicloud.atlassian.net/browse/NH-72398

@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review February 7, 2024 00:49
@tammy-baylis-swi tammy-baylis-swi requested a review from a team as a code owner February 7, 2024 00:49
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, really appreciate the PR description and example data as always @tammy-baylis-swi! Left a few comments.

1. SW_APM_TRANSACTION_NAME
2. AWS_LAMBDA_FUNCTION_NAME
3. automated naming from span name
4. "unknown_service" backup, to match OpenTelemetry SDK Resource default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed adding this to our confluence spec (just did), but the last resort default value should be "unknown"--it's the existing transaction naming logic in the core library so let's keep with it for lambda.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the transaction name should be truncated to 255 chars--this is needed when we export the response time metric via OTLP since the core library is not involved (and thus truncate as it does for the AO proto metrics). Hmm, not sure if Java and Node.js actually conform to this part of the spec currently cc @cleverchuk @raphael-theriault-swi please check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed fallback to "unknown" in 68afe67.

Added sw.transaction truncation in 24d37e8.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope Node doesn't do it at the moment, thanks for pointing this out

@@ -415,6 +419,35 @@ def add_tracestate_capture_to_attributes_dict(
)
return attributes_dict

def calculate_otlp_transaction_name(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes good point, it would be nice to have it shared, although W3C... is very much an HTTP header concern while transaction naming is our SWO-specific concept, so I wouldn't put it there.

There is the top-level apm_txnname_manager, and some other transaction name classes under trace/ that might fit the bill. But you may want to just defer the refactoring until you've had a chance to investigate the idea of subclassing the OTel exporter in order to support custom SDK naming for lambda (which can definitely be a future iteration).

Copy link
Member

@raphael-theriault-swi raphael-theriault-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also looks good to me

Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the revisit @tammy-baylis-swi!

@tammy-baylis-swi tammy-baylis-swi merged commit 4dd99a1 into main Feb 7, 2024
11 checks passed
@tammy-baylis-swi tammy-baylis-swi deleted the NH-69217-sw-trans-attr branch February 7, 2024 21:58
@tammy-baylis-swi
Copy link
Contributor Author

Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants