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

When APM is disabled, OTEL's start_span causes exception #2163

Open
Arvinje opened this issue Nov 27, 2024 · 3 comments
Open

When APM is disabled, OTEL's start_span causes exception #2163

Arvinje opened this issue Nov 27, 2024 · 3 comments
Labels
agent-python community Issues opened by the community triage Issues awaiting triage

Comments

@Arvinje
Copy link

Arvinje commented Nov 27, 2024

Describe the bug: ...
When ELASTIC_APM_ENABLED is set to false, start_span() should not result in an exception. This happens when the Tracer from from elasticapm.contrib.opentelemetry.trace is used.

To Reproduce

  1. Set ELASTIC_APM_ENABLED to false
  2. Call start_as_current_span or start_span (from Tracer of elasticapm.contrib.opentelemetry.trace)
  3. Notice an exception is thrown

Environment (please complete the following information)

  • OS: Mac OS, Linux
  • Python version: 3.12
  • Framework and version [e.g. Django 2.1]: N/A
  • APM Server version: N/A
  • Agent version: 6.23.0

Additional context

Here's the exception:

 with tracer.start_as_current_span(name) as span:\\n    
 |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n    
 |   File \\\"/usr/local/lib/python3.12/contextlib.py\\\", line 137, in __enter__\\n    
 |     return next(self.gen)\\n    
 |            ^^^^^^^^^^^^^^\\n    
 |   File \\\"/app/.venv/lib/python3.12/site-packages/elasticapm/contrib/opentelemetry/trace.py\\\", line 230, in start_as_current_span\\n    
 |     span = self.start_span(\\n    
 |            ^^^^^^^^^^^^^^^^\\n    
 |   File \\\"/app/.venv/lib/python3.12/site-packages/elasticapm/contrib/opentelemetry/trace.py\\\", line 150, in start_span\\n    
 |     span = Span(\\n    
 |            ^^^^^\\n    
 |   File \\\"/app/.venv/lib/python3.12/site-packages/elasticapm/contrib/opentelemetry/span.py\\\", line 65, in __init__\\n    
 |     elastic_span.otel_wrapper = self\\n    
 |     ^^^^^^^^^^^^^^^^^^^^^^^^^\\n    
 | AttributeError: 'NoneType' object has no attribute 'otel_wrapper'\\n
  • Agent config options

    Click to expand
    client = elasticapm.Client(
      central_config=False,
      transaction_sample_rate=1,
    )
    
    tracer = Tracer(__name__)
    
  • requirements.txt:

    Click to expand
    elastic-apm = "^6.23.0"
    opentelemetry-api = "^1.28.1"
    opentelemetry-sdk = "^1.28.1"
    
@github-actions github-actions bot added agent-python community Issues opened by the community triage Issues awaiting triage labels Nov 27, 2024
@xrmx
Copy link
Member

xrmx commented Nov 27, 2024

Thanks for reporting. Wrote a quick test for reproducing this but it still passes, anyway looking at the code I see how it can fail:

diff --git a/tests/contrib/opentelemetry/tests.py b/tests/contrib/opentelemetry/tests.py
index 3a302289..a3e0a705 100755
--- a/tests/contrib/opentelemetry/tests.py
+++ b/tests/contrib/opentelemetry/tests.py
@@ -48,6 +48,19 @@ def tracer(elasticapm_client) -> Tracer:
     yield Tracer("test", elasticapm_client=elasticapm_client)
 
[email protected]("elasticapm_client", [{"enabled": False}], indirect=True)
+def test_root_transaction_not_enabled(elasticapm_client, tracer):
+    with tracer.start_as_current_span("test"):
+        pass
+
+
 def test_root_transaction(tracer: Tracer):
     with tracer.start_as_current_span("test"):
         pass

@xrmx
Copy link
Member

xrmx commented Nov 27, 2024

@Arvinje Does setting OTEL_SDK_DISABLED=true env var help?

@Arvinje
Copy link
Author

Arvinje commented Nov 27, 2024

@xrmx no it doesn't. I hoped similar to the NodeJS package, ELASTIC_APM_ENABLED=false would turn methods of the OTel bridge into noop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-python community Issues opened by the community triage Issues awaiting triage
Projects
None yet
Development

No branches or pull requests

2 participants