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

update: use context instead of trace_id, span_id, trace_flags at eventsAPI #4344

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions opentelemetry-api/src/opentelemetry/_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from opentelemetry.environment_variables import (
_OTEL_PYTHON_EVENT_LOGGER_PROVIDER,
)
from opentelemetry.trace.span import TraceFlags
from opentelemetry.trace.span import SpanContext
from opentelemetry.util._once import Once
from opentelemetry.util._providers import _load_provider
from opentelemetry.util.types import Attributes
Expand All @@ -35,15 +35,18 @@ def __init__(
self,
name: str,
timestamp: Optional[int] = None,
trace_id: Optional[int] = None,
span_id: Optional[int] = None,
trace_flags: Optional["TraceFlags"] = None,
span_context: Optional[SpanContext] = None,
body: Optional[Any] = None,
severity_number: Optional[SeverityNumber] = None,
attributes: Optional[Attributes] = None,
):
attributes = attributes or {}
event_attributes = {**attributes, "event.name": name}
trace_id = span_id = trace_flags = None
if span_context:
trace_id = span_context.trace_id
span_id = span_context.span_id
trace_flags = span_context.trace_flags
super().__init__(
timestamp=timestamp,
trace_id=trace_id,
Expand Down
22 changes: 7 additions & 15 deletions opentelemetry-sdk/tests/events/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,11 @@ def test_event_logger_emit(self, logger_mock, log_record_mock):
"name", "version", "schema_url", {"key": "value"}
)
now = Mock()
trace_id = Mock()
span_id = Mock()
trace_flags = Mock()
span_context = Mock()
event = Event(
name="test_event",
timestamp=now,
trace_id=trace_id,
span_id=span_id,
trace_flags=trace_flags,
span_context=span_context,
body="test body",
severity_number=SeverityNumber.ERROR,
attributes={
Expand All @@ -146,9 +142,9 @@ def test_event_logger_emit(self, logger_mock, log_record_mock):
log_record_mock.assert_called_once_with(
timestamp=now,
observed_timestamp=None,
trace_id=trace_id,
span_id=span_id,
trace_flags=trace_flags,
trace_id=span_context.trace_id,
span_id=span_context.span_id,
trace_flags=span_context.trace_flags,
severity_text=None,
severity_number=SeverityNumber.ERROR,
body="test body",
Expand Down Expand Up @@ -179,15 +175,11 @@ def test_event_logger_emit_sdk_disabled(
"name", "version", "schema_url", {"key": "value"}
)
now = Mock()
trace_id = Mock()
span_id = Mock()
trace_flags = Mock()
span_context = Mock()
event = Event(
name="test_event",
timestamp=now,
trace_id=trace_id,
span_id=span_id,
trace_flags=trace_flags,
span_context=span_context,
body="test body",
severity_number=SeverityNumber.ERROR,
attributes={
Expand Down
Loading