-
Notifications
You must be signed in to change notification settings - Fork 133
Hybrid agent ASGI, DB Traces, and External Traces support #1617
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
Changes from all commits
d90de11
0b04de0
0ea3e2c
75a57f4
7586edf
d95f7a0
044e9b9
1e8adfa
c92ed69
d61b26c
2240552
1b5ba1d
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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
|
|
||
| from botocore.response import StreamingBody | ||
|
|
||
| from newrelic.core.database_utils import generate_dynamodb_arn | ||
| from newrelic.api.datastore_trace import DatastoreTrace | ||
| from newrelic.api.external_trace import ExternalTrace | ||
| from newrelic.api.function_trace import FunctionTrace | ||
|
|
@@ -1295,21 +1296,10 @@ def _nr_dynamodb_datastore_trace_wrapper_(wrapped, instance, args, kwargs): | |
| settings = transaction.settings if transaction.settings else global_settings() | ||
| account_id = settings.cloud.aws.account_id if settings and settings.cloud.aws.account_id else None | ||
|
|
||
| # There are 3 different partition options. | ||
| # See https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html for details. | ||
| partition = None | ||
| if hasattr(instance, "_endpoint") and hasattr(instance._endpoint, "host"): | ||
| _db_host = instance._endpoint.host | ||
| partition = "aws" | ||
| if "amazonaws.cn" in _db_host: | ||
| partition = "aws-cn" | ||
| elif "amazonaws-us-gov.com" in _db_host: | ||
| partition = "aws-us-gov" | ||
|
|
||
| if partition and region and account_id and _target: | ||
| agent_attrs["cloud.resource_id"] = ( | ||
| f"arn:{partition}:dynamodb:{region}:{account_id:012d}:table/{_target}" | ||
| ) | ||
| _db_host = getattr(getattr(instance, "_endpoint", None), "host", None) | ||
| resource_id = generate_dynamodb_arn(_db_host, region, account_id, _target) | ||
| if resource_id: | ||
| agent_attrs["cloud.resource_id"] = resource_id | ||
|
|
||
| except Exception: | ||
| _logger.debug("Failed to capture AWS DynamoDB info.", exc_info=True) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,6 @@ | |
| def wrap__load_runtime_context(wrapped, instance, args, kwargs): | ||
| application = application_instance(activate=False) | ||
| settings = global_settings() if not application else application.settings | ||
|
|
||
| if not settings.opentelemetry.enabled: | ||
| return wrapped(*args, **kwargs) | ||
|
|
||
|
|
@@ -52,16 +51,14 @@ def wrap__load_runtime_context(wrapped, instance, args, kwargs): | |
| def wrap_get_global_response_propagator(wrapped, instance, args, kwargs): | ||
| application = application_instance(activate=False) | ||
| settings = global_settings() if not application else application.settings | ||
|
|
||
| if not settings.opentelemetry.enabled: | ||
| return wrapped(*args, **kwargs) | ||
|
|
||
| from opentelemetry.instrumentation.propagators import set_global_response_propagator | ||
|
|
||
| from newrelic.api.opentelemetry import otel_context_propagator | ||
|
|
||
| from opentelemetry.instrumentation.propagators import set_global_response_propagator | ||
|
|
||
| set_global_response_propagator(otel_context_propagator) | ||
|
|
||
| return otel_context_propagator | ||
|
|
||
|
|
||
|
|
@@ -91,12 +88,10 @@ def wrap_set_tracer_provider(wrapped, instance, args, kwargs): | |
| application.activate() | ||
|
|
||
| settings = global_settings() if not application else application.settings | ||
|
|
||
| if not settings: | ||
| # The application may need more time to start up | ||
| time.sleep(0.5) | ||
| settings = global_settings() if not application else application.settings | ||
|
|
||
| if not settings or not settings.opentelemetry.enabled: | ||
| return wrapped(*args, **kwargs) | ||
|
|
||
|
|
@@ -137,9 +132,8 @@ def wrap_get_tracer_provider(wrapped, instance, args, kwargs): | |
|
|
||
| if _TRACER_PROVIDER is None: | ||
| from newrelic.api.opentelemetry import TracerProvider | ||
|
|
||
| hybrid_agent_tracer_provider = TracerProvider("hybrid_agent_tracer_provider") | ||
| _TRACER_PROVIDER = hybrid_agent_tracer_provider | ||
| _TRACER_PROVIDER = TracerProvider() | ||
|
Contributor
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. Just making sure we don't still need to pass
Contributor
Author
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. Oh, I changed this logic slightly to be more in line with the actual TracerProvider's functionality. I'll flesh it out some more in the future, but basically, the OTel TracerProvider doesn't really take in a name. |
||
|
|
||
| return _TRACER_PROVIDER | ||
|
|
||
|
|
||
|
|
@@ -226,6 +220,8 @@ def wrap_start_internal_or_server_span(wrapped, instance, args, kwargs): | |
| # This is an HTTP request (WSGI, ASGI, or otherwise) | ||
| if "wsgi.version" in context_carrier: | ||
| attributes["nr.wsgi.environ"] = context_carrier | ||
| elif "asgi" in context_carrier: | ||
| attributes["nr.asgi.scope"] = context_carrier | ||
| else: | ||
| attributes["nr.http.headers"] = context_carrier | ||
| else: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.