Skip to content

Commit 351b52b

Browse files
authored
Merge branch 'main' into cleanup/remove-pylint-disable-celery
2 parents 2b9d102 + 05113dc commit 351b52b

27 files changed

Lines changed: 2579 additions & 84 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
([#4457](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4457))
2222
- Remove redundant `pylint: disable=attribute-defined-outside-init` comments and add rule to global `.pylintrc` disable list
2323
([#3839](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3839))
24+
- `opentelemetry-exporter-richconsole`: Add support for suppressing resource information
25+
([#3898](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3898))
2426

2527
### Fixed
2628

exporter/opentelemetry-exporter-richconsole/src/opentelemetry/exporter/richconsole/__init__.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ def _ns_to_time(nanoseconds):
7676
return ts.strftime("%H:%M:%S.%f")
7777

7878

79-
def _child_to_tree(child: Tree, span: ReadableSpan):
79+
def _child_to_tree(
80+
child: Tree, span: ReadableSpan, *, suppress_resource: bool
81+
):
8082
child.add(
8183
Text.from_markup(f"[bold cyan]Kind :[/bold cyan] {span.kind.name}")
8284
)
8385
_add_status(child, span)
84-
_child_add_optional_attributes(child, span)
86+
_child_add_optional_attributes(
87+
child, span, suppress_resource=suppress_resource
88+
)
8589

8690

8791
def _add_status(child: Tree, span: ReadableSpan):
@@ -106,7 +110,9 @@ def _add_status(child: Tree, span: ReadableSpan):
106110
)
107111

108112

109-
def _child_add_optional_attributes(child: Tree, span: ReadableSpan):
113+
def _child_add_optional_attributes(
114+
child: Tree, span: ReadableSpan, *, suppress_resource: bool
115+
):
110116
if span.events:
111117
events = child.add(
112118
label=Text.from_markup("[bold cyan]Events :[/bold cyan] ")
@@ -133,7 +139,7 @@ def _child_add_optional_attributes(child: Tree, span: ReadableSpan):
133139
f"[bold cyan]{attribute} :[/bold cyan] {span.attributes[attribute]}"
134140
)
135141
)
136-
if span.resource:
142+
if span.resource and not suppress_resource:
137143
resources = child.add(
138144
label=Text.from_markup("[bold cyan]Resources :[/bold cyan] ")
139145
)
@@ -155,21 +161,29 @@ class RichConsoleSpanExporter(SpanExporter):
155161
def __init__(
156162
self,
157163
service_name: Optional[str] = None,
164+
suppress_resource: bool = False,
158165
):
159166
self.service_name = service_name
167+
self.suppress_resource = suppress_resource
160168
self.console = Console()
161169

162170
def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
163171
if not spans:
164172
return SpanExportResult.SUCCESS
165173

166-
for tree in self.spans_to_tree(spans).values():
174+
for tree in self.spans_to_tree(
175+
spans, suppress_resource=self.suppress_resource
176+
).values():
167177
self.console.print(tree)
168178

169179
return SpanExportResult.SUCCESS
170180

171181
@staticmethod
172-
def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
182+
def spans_to_tree(
183+
spans: typing.Sequence[ReadableSpan],
184+
*,
185+
suppress_resource: bool = False,
186+
) -> Dict[str, Tree]:
173187
trees = {}
174188
parents = {}
175189
spans = list(spans)
@@ -189,7 +203,9 @@ def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
189203
)
190204
)
191205
parents[span.context.span_id] = child
192-
_child_to_tree(child, span)
206+
_child_to_tree(
207+
child, span, suppress_resource=suppress_resource
208+
)
193209
spans.remove(span)
194210
elif span.parent and span.parent.span_id in parents:
195211
child = parents[span.parent.span_id].add(
@@ -198,6 +214,8 @@ def spans_to_tree(spans: typing.Sequence[ReadableSpan]) -> Dict[str, Tree]:
198214
)
199215
)
200216
parents[span.context.span_id] = child
201-
_child_to_tree(child, span)
217+
_child_to_tree(
218+
child, span, suppress_resource=suppress_resource
219+
)
202220
spans.remove(span)
203221
return trees

exporter/opentelemetry-exporter-richconsole/tests/test_rich_exporter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
# limitations under the License.
1414

1515
import pytest
16+
from rich.text import Text
1617
from rich.tree import Tree
1718

1819
import opentelemetry.trace
1920
from opentelemetry.exporter.richconsole import RichConsoleSpanExporter
2021
from opentelemetry.sdk import trace
22+
from opentelemetry.sdk.resources import Resource
2123
from opentelemetry.sdk.trace.export import BatchSpanProcessor
2224

2325

@@ -108,3 +110,30 @@ def test_no_deadlock(tracer_provider):
108110
pass
109111

110112
RichConsoleSpanExporter.spans_to_tree((child,))
113+
114+
115+
def test_suppress_resource(span_processor):
116+
attributes = {"resource.key": "resource.value"}
117+
resource = Resource(attributes)
118+
tracer_provider = trace.TracerProvider(resource=resource)
119+
tracer_provider.add_span_processor(span_processor)
120+
tracer = tracer_provider.get_tracer(__name__)
121+
122+
with tracer.start_as_current_span("parent") as parent:
123+
with tracer.start_as_current_span("child") as child:
124+
pass
125+
126+
trees = RichConsoleSpanExporter.spans_to_tree(
127+
(parent, child), suppress_resource=True
128+
)
129+
assert len(trees) == 1
130+
131+
nodes = [next(t for t in trees.values())]
132+
for node in nodes:
133+
label = node.label
134+
if isinstance(label, Text):
135+
label = label.plain
136+
137+
assert "resource" not in label.lower()
138+
139+
nodes.extend(node.children)

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pythonVersion = "3.10"
202202
reportPrivateUsage = false # Ignore private attributes added by instrumentation packages.
203203
# Add progressively instrumentation packages here.
204204
include = [
205+
"instrumentation/opentelemetry-instrumentation-aiohttp-client",
205206
"instrumentation/opentelemetry-instrumentation-aiokafka",
206207
"instrumentation/opentelemetry-instrumentation-asyncclick",
207208
"instrumentation/opentelemetry-instrumentation-threading",
@@ -214,6 +215,7 @@ include = [
214215
"exporter/opentelemetry-exporter-credential-provider-gcp",
215216
"instrumentation/opentelemetry-instrumentation-aiohttp-client",
216217
"opamp/opentelemetry-opamp-client",
218+
"sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace",
217219
]
218220
# We should also add type hints to the test suite - It helps on finding bugs.
219221
# We are excluding for now because it's easier, and more important to add to the instrumentation packages.

sdk-extension/opentelemetry-sdk-extension-aws/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- Add caching, matching, and targets logic to complete AWS X-Ray Remote Sampler implementation
13+
([#3366](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3761))
14+
1015
## Version 2.1.0 (2024-12-24)
1116

1217
- Make ec2 resource detector silent when loaded outside AWS

sdk-extension/opentelemetry-sdk-extension-aws/README.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ populate `resource` attributes by creating a `TraceProvider` using the `AwsEc2Re
7474
Refer to each detectors' docstring to determine any possible requirements for that
7575
detector.
7676

77+
78+
Usage (AWS X-Ray Remote Sampler)
79+
--------------------------------
80+
81+
Use the provided AWS X-Ray Remote Sampler by setting this sampler in your instrumented application:
82+
83+
.. code-block:: python
84+
85+
from opentelemetry.sdk.extension.aws.trace.sampler import AwsXRayRemoteSampler
86+
from opentelemetry import trace
87+
from opentelemetry.sdk.resources import Resource
88+
from opentelemetry.sdk.trace import TracerProvider
89+
from opentelemetry.semconv.resource import ResourceAttributes
90+
from opentelemetry.util.types import Attributes
91+
92+
resource = Resource.create(attributes={
93+
ResourceAttributes.SERVICE_NAME: "myService",
94+
ResourceAttributes.CLOUD_PLATFORM: "aws_ec2",
95+
})
96+
xraySampler = AwsXRayRemoteSampler(resource=resource, polling_interval=300)
97+
trace.set_tracer_provider(TracerProvider(sampler=xraySampler))
98+
99+
77100
References
78101
----------
79102

sdk-extension/opentelemetry-sdk-extension-aws/pyproject.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ classifiers = [
2525
"Programming Language :: Python :: 3.14",
2626
]
2727
dependencies = [
28-
"opentelemetry-api ~= 1.23",
29-
"opentelemetry-sdk ~= 1.23",
30-
"opentelemetry-instrumentation ~= 0.44b0",
31-
"opentelemetry-semantic-conventions ~= 0.44b0",
28+
"opentelemetry-api ~= 1.26",
29+
"opentelemetry-sdk ~= 1.26",
30+
"opentelemetry-instrumentation ~= 0.47b0",
31+
"opentelemetry-semantic-conventions ~= 0.47b0",
3232
"requests ~= 2.28",
3333
]
3434

@@ -42,9 +42,8 @@ aws_eks = "opentelemetry.sdk.extension.aws.resource.eks:AwsEksResourceDetector"
4242
aws_elastic_beanstalk = "opentelemetry.sdk.extension.aws.resource.beanstalk:AwsBeanstalkResourceDetector"
4343
aws_lambda = "opentelemetry.sdk.extension.aws.resource._lambda:AwsLambdaResourceDetector"
4444

45-
# TODO: Uncomment this when Sampler implementation is complete
46-
# [project.entry-points.opentelemetry_sampler]
47-
# aws_xray_remote_sampler = "opentelemetry.sdk.extension.aws.trace.sampler:AwsXRayRemoteSampler"
45+
[project.entry-points.opentelemetry_sampler]
46+
aws_xray_remote_sampler = "opentelemetry.sdk.extension.aws.trace.sampler:AwsXRayRemoteSampler"
4847

4948
[project.urls]
5049
Homepage = "https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/sdk-extension/opentelemetry-sdk-extension-aws"

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# pylint: disable=no-name-in-module
1616
from opentelemetry.sdk.extension.aws.trace.sampler.aws_xray_remote_sampler import (
17-
_AwsXRayRemoteSampler,
17+
AwsXRayRemoteSampler,
1818
)
1919

20-
__all__ = ["_AwsXRayRemoteSampler"]
20+
__all__ = ["AwsXRayRemoteSampler"]

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/_aws_xray_sampling_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
DEFAULT_SAMPLING_PROXY_ENDPOINT = "http://127.0.0.1:2000"
3838

3939

40-
class _AwsXRaySamplingClient:
40+
class _AwsXRaySamplingClient: # pyright: ignore[reportUnusedClass]
4141
def __init__(
4242
self,
4343
endpoint: str = DEFAULT_SAMPLING_PROXY_ENDPOINT,

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/sampler/_clock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import datetime
2020

2121

22-
class _Clock:
22+
class _Clock: # pyright: ignore[reportUnusedClass]
2323
def __init__(self):
2424
self.__datetime = datetime.datetime
2525

0 commit comments

Comments
 (0)