-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 5 commits
d3653ca
50323d9
9ca9bda
ed02457
dabe6cf
68afe67
24d37e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
INTL_SWO_COMMA_W3C_SANITIZED, | ||
INTL_SWO_EQUALS_W3C_SANITIZED, | ||
INTL_SWO_TRACESTATE_KEY, | ||
INTL_SWO_TRANSACTION_ATTR_KEY, | ||
INTL_SWO_X_OPTIONS_KEY, | ||
INTL_SWO_X_OPTIONS_RESPONSE_KEY, | ||
) | ||
|
@@ -69,6 +70,9 @@ def __init__( | |
oboe_api: "OboeAPI", | ||
): | ||
self.apm_config = apm_config | ||
# SW_APM_TRANSACTION_NAME and AWS_LAMBDA_FUNCTION_NAME | ||
self.env_transaction_name = apm_config.get("transaction_name") | ||
self.lambda_function_name = apm_config.lambda_function_name | ||
self.context = apm_config.extension.Context | ||
|
||
if self.apm_config.get("tracing_mode") is not None: | ||
|
@@ -415,6 +419,35 @@ def add_tracestate_capture_to_attributes_dict( | |
) | ||
return attributes_dict | ||
|
||
def calculate_otlp_transaction_name( | ||
self, | ||
span_name: str, | ||
) -> str: | ||
"""Calculate transaction name for OTLP trace following this order | ||
of decreasing precedence: | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
Notes: | ||
* Spans at time of sampling decision/on_start will not have access | ||
to SDK-set names, nor all span attributes from instrumentors | ||
* But they should have access to span `name` | ||
* Spans at on_end are immutable | ||
""" | ||
if self.env_transaction_name: | ||
return self.env_transaction_name | ||
|
||
if self.lambda_function_name: | ||
return self.lambda_function_name | ||
|
||
if span_name: | ||
return span_name | ||
|
||
return "unknown_service" | ||
|
||
def calculate_attributes( | ||
self, | ||
span_name: str, | ||
|
@@ -462,6 +495,18 @@ def calculate_attributes( | |
f"{decision['bucket_rate']}" | ||
) | ||
|
||
# If `experimental` and `otel_collector`, | ||
# always (root or is_remote) set sw.transaction | ||
# TODO Clean up use of experimental trace flag | ||
# https://swicloud.atlassian.net/browse/NH-65067 | ||
if self.apm_config.get("experimental").get("otel_collector") is True: | ||
logger.debug( | ||
"Experimental otel_collector flag configured. Setting sw.transaction on span." | ||
) | ||
new_attributes[INTL_SWO_TRANSACTION_ATTR_KEY] = ( | ||
self.calculate_otlp_transaction_name(span_name) | ||
) | ||
|
||
# sw.tracestate_parent_id is set if: | ||
# 1. the future span is the entry span of a service | ||
# 2. there exists a (remote) parent span | ||
|
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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 undertrace/
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).There was a problem hiding this comment.
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