elastic / elastic/apm-agent-python

When APM is disabled, OTEL's `start_span` causes exception

Aperta
#2,163 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
agent-python community triage
Lingua principale
Python
Stelle
431
Fork
239
Merge medio
5g 10h
PR unite (30g)
7

Descrizione

**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"
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.