Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored Mar 17, 2022
2 parents d649459 + 2f74c90 commit dc0987a
Show file tree
Hide file tree
Showing 16 changed files with 513 additions and 27 deletions.
19 changes: 13 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.10.0-0.29b0...HEAD)

## [1.10.0-0.29b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.10.0-0.29b0) - 2022-03-10

- `opentelemetry-instrumentation-flask` Fix non-recording span bug
([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999)
- `opentelemetry-instrumentation-tornado` Fix non-recording span bug
([#999])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/999)
- `opentelemetry-instrumentation-pyramid` Fixed which package is the correct caller in _traced_init.
([#830](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/830))

## [1.10.0-0.29b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.10.0-0.29b0) - 2022-03-10

- `opentelemetry-instrumentation-wsgi` Capture custom request/response headers in span attributes
([#925])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/925)
- `opentelemetry-instrumentation-pyramid` Fixed which package is the correct caller in _traced_init.
([#830](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/830))

- `opentelemetry-instrumentation-flask` Flask: Capture custom request/response headers in span attributes
([#952])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/952)

- `opentelemetry-instrumentation-tornado` Tornado: Capture custom request/response headers in span attributes
([#950])(https://github.com/open-telemetry/opentelemetry-python-contrib/pull/950)

Expand All @@ -27,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-aws-lambda` `SpanKind.SERVER` by default, add more cases for `SpanKind.CONSUMER` services. ([#926](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/926))
- `opentelemetry-instrumentation-sqlalchemy` added experimental sql commenter capability
([#924](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/924))
- `opentelemetry-contrib-instrumentations` added new meta-package that installs all contrib instrumentations.
([#681](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/681))
- `opentelemetry-instrumentation-dbapi` add experimental sql commenter capability
([#908](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/908))
- `opentelemetry-instrumentation-requests` make span attribute available to samplers
Expand All @@ -37,12 +40,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- `opentelemetry-instrumentation-dbapi` Changed the format of traceparent id.
([#941](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/941))
- `opentelemetry-instrumentation-logging` retrieves service name defensively.
([#890](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/890))
- `opentelemetry-instrumentation-wsgi` WSGI: Conditionally create SERVER spans
([#903](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/903))
- `opentelemetry-instrumentation-falcon` Safer patching mechanism
([#895](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/895))
- `opentelemetry-instrumentation-kafka-python` Fix topic extraction
([#949](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/949))

## [1.9.1-0.28b1](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.9.1-0.28b1) - 2022-01-29

Expand Down
2 changes: 2 additions & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ sqlalchemy>=1.0
tornado>=5.1.1
ddtrace>=0.34.0
httpx>=0.18.0

# indirect dependency pins
markupsafe==2.0.1
itsdangerous==2.0.1
1 change: 1 addition & 0 deletions eachdist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ packages=
opentelemetry-semantic-conventions
opentelemetry-test-utils
opentelemetry-instrumentation
opentelemetry-contrib-instrumentations
opentelemetry-distro

[exclude_release]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@

from opentelemetry import trace as trace_api
from opentelemetry.instrumentation.dbapi.version import __version__
from opentelemetry.instrumentation.utils import _generate_sql_comment, unwrap
from opentelemetry.instrumentation.utils import (
_generate_opentelemetry_traceparent,
_generate_sql_comment,
unwrap,
)
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import Span, SpanKind, TracerProvider, get_tracer

Expand Down Expand Up @@ -369,14 +373,7 @@ def _generate_comment(span: Span) -> str:
span_context = span.get_span_context()
meta = {}
if span_context.is_valid:
meta.update(
{
"trace_id": span_context.trace_id,
"span_id": span_context.span_id,
"trace_flags": span_context.trace_flags,
"trace_state": span_context.trace_state.to_header(),
}
)
meta.update(_generate_opentelemetry_traceparent(span))
# TODO(schekuri): revisit to enrich with info such as route, db_driver etc...
return _generate_sql_comment(**meta)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ def _start_response(status, response_headers, *args, **kwargs):
otel_wsgi.add_response_attributes(
span, status, response_headers
)
if span.kind == trace.SpanKind.SERVER:
if (
span.is_recording()
and span.kind == trace.SpanKind.SERVER
):
otel_wsgi.add_custom_response_headers(
span, response_headers
)
Expand Down Expand Up @@ -204,7 +207,7 @@ def _before_request():
] = flask.request.url_rule.rule
for key, value in attributes.items():
span.set_attribute(key, value)
if span.kind == trace.SpanKind.SERVER:
if span.is_recording() and span.kind == trace.SpanKind.SERVER:
otel_wsgi.add_custom_request_headers(
span, flask_request_environ
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def _extract_argument(key, position, default_value, args, kwargs):
return kwargs.get(key, default_value)

@staticmethod
def extract_send_topic(args):
def extract_send_topic(args, kwargs):
"""extract topic from `send` method arguments in KafkaProducer class"""
if len(args) > 0:
return args[0]
return "unknown"
return KafkaPropertiesExtractor._extract_argument(
"topic", 0, "unknown", args, kwargs
)

@staticmethod
def extract_send_value(args, kwargs):
Expand All @@ -56,7 +56,7 @@ def extract_send_headers(args, kwargs):
def extract_send_partition(instance, args, kwargs):
"""extract partition `send` method arguments, using the `_partition` method in KafkaProducer class"""
try:
topic = KafkaPropertiesExtractor.extract_send_topic(args)
topic = KafkaPropertiesExtractor.extract_send_topic(args, kwargs)
key = KafkaPropertiesExtractor.extract_send_key(args, kwargs)
value = KafkaPropertiesExtractor.extract_send_value(args, kwargs)
partition = KafkaPropertiesExtractor._extract_argument(
Expand Down Expand Up @@ -145,7 +145,7 @@ def _traced_send(func, instance, args, kwargs):
headers = []
kwargs["headers"] = headers

topic = KafkaPropertiesExtractor.extract_send_topic(args)
topic = KafkaPropertiesExtractor.extract_send_topic(args, kwargs)
bootstrap_servers = KafkaPropertiesExtractor.extract_bootstrap_servers(
instance
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,57 @@ def setUp(self) -> None:
@mock.patch("opentelemetry.instrumentation.kafka.utils._enrich_span")
@mock.patch("opentelemetry.trace.set_span_in_context")
@mock.patch("opentelemetry.propagate.inject")
def test_wrap_send(
def test_wrap_send_with_topic_as_arg(
self,
inject: mock.MagicMock,
set_span_in_context: mock.MagicMock,
enrich_span: mock.MagicMock,
extract_send_partition: mock.MagicMock,
extract_bootstrap_servers: mock.MagicMock,
):
) -> None:
self.wrap_send_helper(
inject,
set_span_in_context,
enrich_span,
extract_send_partition,
extract_bootstrap_servers,
)

@mock.patch(
"opentelemetry.instrumentation.kafka.utils.KafkaPropertiesExtractor.extract_bootstrap_servers"
)
@mock.patch(
"opentelemetry.instrumentation.kafka.utils.KafkaPropertiesExtractor.extract_send_partition"
)
@mock.patch("opentelemetry.instrumentation.kafka.utils._enrich_span")
@mock.patch("opentelemetry.trace.set_span_in_context")
@mock.patch("opentelemetry.propagate.inject")
def test_wrap_send_with_topic_as_kwarg(
self,
inject: mock.MagicMock,
set_span_in_context: mock.MagicMock,
enrich_span: mock.MagicMock,
extract_send_partition: mock.MagicMock,
extract_bootstrap_servers: mock.MagicMock,
) -> None:
self.args = []
self.kwargs["topic"] = self.topic_name
self.wrap_send_helper(
inject,
set_span_in_context,
enrich_span,
extract_send_partition,
extract_bootstrap_servers,
)

def wrap_send_helper(
self,
inject: mock.MagicMock,
set_span_in_context: mock.MagicMock,
enrich_span: mock.MagicMock,
extract_send_partition: mock.MagicMock,
extract_bootstrap_servers: mock.MagicMock,
) -> None:
tracer = mock.MagicMock()
produce_hook = mock.MagicMock()
original_send_callback = mock.MagicMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def _start_span(tracer, handler, start_time) -> _TraceContext:
for key, value in attributes.items():
span.set_attribute(key, value)
span.set_attribute("tornado.handler", _get_full_handler_name(handler))
if span.kind == trace.SpanKind.SERVER:
if span.is_recording() and span.kind == trace.SpanKind.SERVER:
_add_custom_request_headers(span, handler.request.headers)

activation = trace.use_span(span, end_on_exit=True)
Expand Down Expand Up @@ -395,7 +395,7 @@ def _finish_span(tracer, handler, error=None):
description=otel_status_description,
)
)
if ctx.span.kind == trace.SpanKind.SERVER:
if ctx.span.is_recording() and ctx.span.kind == trace.SpanKind.SERVER:
_add_custom_response_headers(ctx.span, handler._headers)

ctx.activation.__exit__(*finish_args) # pylint: disable=E1101
Expand Down
Loading

0 comments on commit dc0987a

Please sign in to comment.