open-telemetry / open-telemetry/opentelemetry-python

How can I configure OpenTelemetry to ​​disable Span creation​​ and ​​only collect Metrics​​ (without Traces or Logs)?

Open
#4,757 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

Describe your environment

OS: linux
Python version: Python 3.11

How can I configure OpenTelemetry to ​​disable Span creation​​ and ​​only collect Metrics​​ (without Traces or Logs)?

What happened?

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 1839, in _handle_request_exception
self.log_exception(*sys.exc_info())
File "/otel-auto-instrumentation/wrapt/wrappers.py", line 670, in call
return self._self_wrapper(self.wrapped, self._self_instance,
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 442, in _log_exception
_record_on_finish_metrics(server_histograms, handler, error)
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 635, in _record_on_finish_metrics
server_histograms[MetricInstruments.HTTP_SERVER_RESPONSE_SIZE].record(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/instrument.py", line 264, in record
self._measurement_consumer.consume_measurement(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/measurement_consumer.py", line 82, in consume_measurement
self._sdk_config.exemplar_filter.should_sample(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py", line 131, in should_sample
span = trace.get_current_span(context)
File "/otel-auto-instrumentation/opentelemetry/trace/propagation/init.py", line 48, in get_current_span
span = get_value(_SPAN_KEY, context=context)
File "/otel-auto-instrumentation/opentelemetry/context/init.py", line 97, in get_value
return context.get(key) if context is not None else get_current().get(key)
AttributeError: 'NoneType' object has no attribute 'get'
500 GET /health (10.231.248.38) 1.15ms
Uncaught exception in write_error
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 1767, in _execute
result = self.prepare()
File "/otel-auto-instrumentation/wrapt/wrappers.py", line 670, in call
return self._self_wrapper(self.wrapped, self._self_instance,
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 413, in _prepare
ctx = _start_span(tracer, handler)
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 522, in _start_span
span, token = _start_internal_or_server_span(
File "/otel-auto-instrumentation/opentelemetry/instrumentation/utils.py", line 147, in _start_internal_or_server_span
span = tracer.start_span(
File "/otel-auto-instrumentation/opentelemetry/sdk/trace/init.py", line 1118, in start_span
parent_span_context = trace_api.get_current_span(
File "/otel-auto-instrumentation/opentelemetry/trace/propagation/init.py", line 48, in get_current_span
span = get_value(_SPAN_KEY, context=context)
File "/otel-auto-instrumentation/opentelemetry/context/init.py", line 97, in get_value
return context.get(key) if context is not None else get_current().get(key)
AttributeError: 'NoneType' object has no attribute 'get'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 1298, in send_error
self.write_error(status_code, **kwargs)
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 1323, in write_error
self.finish(
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 1242, in finish
self.on_finish()
File "/otel-auto-instrumentation/wrapt/wrappers.py", line 670, in call
return self._self_wrapper(self.wrapped, self._self_instance,
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 423, in _on_finish
_record_on_finish_metrics(server_histograms, handler)
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 635, in _record_on_finish_metrics
server_histograms[MetricInstruments.HTTP_SERVER_RESPONSE_SIZE].record(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/instrument.py", line 264, in record
self._measurement_consumer.consume_measurement(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/measurement_consumer.py", line 82, in consume_measurement
self._sdk_config.exemplar_filter.should_sample(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py", line 131, in should_sample
span = trace.get_current_span(context)
File "/otel-auto-instrumentation/opentelemetry/trace/propagation/init.py", line 48, in get_current_span
span = get_value(_SPAN_KEY, context=context)
File "/otel-auto-instrumentation/opentelemetry/context/init.py", line 97, in get_value
return context.get(key) if context is not None else get_current().get(key)
AttributeError: 'NoneType' object has no attribute 'get'
Exception in callback _HandlerDelegate.execute..(<Task finishe...ibute 'get'")>) at /usr/local/lib/python3.10/site-packages/tornado/web.py:2438
handle: <Handle _HandlerDelegate.execute..(<Task finishe...ibute 'get'")>) at /usr/local/lib/python3.10/site-packages/tornado/web.py:2438>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 2438, in
fut.add_done_callback(lambda f: f.result())
File "/otel-auto-instrumentation/opentelemetry/instrumentation/asyncio/init.py", line 314, in trace_coroutine
self.record_process(start, attr, span, exception)
File "/otel-auto-instrumentation/opentelemetry/instrumentation/asyncio/init.py", line 358, in record_process
self.process_duration_histogram.record(duration, attr)
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/instrument.py", line 264, in record
self._measurement_consumer.consume_measurement(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/measurement_consumer.py", line 82, in consume_measurement
self._sdk_config.exemplar_filter.should_sample(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py", line 131, in should_sample
span = trace.get_current_span(context)
File "/otel-auto-instrumentation/opentelemetry/trace/propagation/init.py", line 48, in get_current_span
span = get_value(_SPAN_KEY, context=context)
File "/otel-auto-instrumentation/opentelemetry/context/init.py", line 97, in get_value
return context.get(key) if context is not None else get_current().get(key)
AttributeError: 'NoneType' object has no attribute 'get'
Error in exception logger
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 1767, in _execute
result = self.prepare()
File "/otel-auto-instrumentation/wrapt/wrappers.py", line 670, in call
return self._self_wrapper(self.wrapped, self._self_instance,
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 413, in _prepare
ctx = _start_span(tracer, handler)
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 522, in _start_span
span, token = _start_internal_or_server_span(
File "/otel-auto-instrumentation/opentelemetry/instrumentation/utils.py", line 147, in _start_internal_or_server_span
span = tracer.start_span(
File "/otel-auto-instrumentation/opentelemetry/sdk/trace/init.py", line 1118, in start_span
parent_span_context = trace_api.get_current_span(
File "/otel-auto-instrumentation/opentelemetry/trace/propagation/init.py", line 48, in get_current_span
span = get_value(_SPAN_KEY, context=context)
File "/otel-auto-instrumentation/opentelemetry/context/init.py", line 97, in get_value
return context.get(key) if context is not None else get_current().get(key)
AttributeError: 'NoneType' object has no attribute 'get'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/tornado/web.py", line 1839, in _handle_request_exception
self.log_exception(*sys.exc_info())
File "/otel-auto-instrumentation/wrapt/wrappers.py", line 670, in call
return self._self_wrapper(self.wrapped, self._self_instance,
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 442, in _log_exception
_record_on_finish_metrics(server_histograms, handler, error)
File "/otel-auto-instrumentation/opentelemetry/instrumentation/tornado/init.py", line 635, in _record_on_finish_metrics
server_histograms[MetricInstruments.HTTP_SERVER_RESPONSE_SIZE].record(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/instrument.py", line 264, in record
self._measurement_consumer.consume_measurement(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/measurement_consumer.py", line 82, in consume_measurement
self._sdk_config.exemplar_filter.should_sample(
File "/otel-auto-instrumentation/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_filter.py", line 131, in should_sample
span = trace.get_current_span(context)
File "/otel-auto-instrumentation/opentelemetry/trace/propagation/init.py", line 48, in get_current_span
span = get_value(_SPAN_KEY, context=context)
File "/otel-auto-instrumentation/opentelemetry/context/init.py", line 97, in get_value
return context.get(key) if context is not None else get_current().get(key)
AttributeError: 'NoneType' object has no attribute 'get'

Steps to Reproduce

none

Expected Result

none

Actual Result

none

Additional context

none

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with opentelemetry/instrumentation/tornado/init.py around _start_span and _record_on_finish_metrics, then inspect sdk/metrics/_internal/exemplar/exemplar_filter.py and trace/propagation/init.py for the None context failure. Reproduce the reported Linux/Python setup if possible and establish whether metrics-only configuration can avoid the traceback while preserving metrics; done requires a confirmed configuration or clearly scoped fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.