Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 66c6d0f

Browse files
committed
fix: add trace settings to filter spans before export
1 parent 3128beb commit 66c6d0f

6 files changed

Lines changed: 86 additions & 29 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[project]
22
name = "uipath-core"
3-
version = "0.1.10"
3+
version = "0.2.0"
44
description = "UiPath Core abstractions"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"
77
dependencies = [
8-
"opentelemetry-sdk>=1.39.0, <2.0.0",
9-
"opentelemetry-instrumentation>=0.60b0, <1.0.0",
8+
"opentelemetry-sdk>=1.39.1, <2.0.0",
9+
"opentelemetry-instrumentation>=0.60b1, <1.0.0",
1010
"pydantic>=2.12.5, <3.0.0",
1111
]
1212
classifiers = [

src/uipath/core/tracing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from uipath.core.tracing.decorators import traced
88
from uipath.core.tracing.span_utils import UiPathSpanUtils
99
from uipath.core.tracing.trace_manager import UiPathTraceManager
10+
from uipath.core.tracing.types import UiPathTraceSettings
1011

1112
__all__ = [
1213
"traced",
1314
"UiPathSpanUtils",
1415
"UiPathTraceManager",
16+
"UiPathTraceSettings",
1517
]

src/uipath/core/tracing/processors.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
"""Custom span processors for UiPath execution tracing."""
22

3-
from typing import Optional, cast
3+
from typing import cast
44

55
from opentelemetry import context as context_api
66
from opentelemetry import trace
7-
from opentelemetry.sdk.trace import Span
7+
from opentelemetry.sdk.trace import ReadableSpan, Span
88
from opentelemetry.sdk.trace.export import (
99
BatchSpanProcessor,
1010
SimpleSpanProcessor,
11+
SpanExporter,
12+
SpanProcessor,
1113
)
1214

15+
from uipath.core.tracing.types import UiPathTraceSettings
16+
1317

1418
class UiPathExecutionTraceProcessorMixin:
15-
def on_start(
16-
self, span: Span, parent_context: Optional[context_api.Context] = None
17-
):
19+
"""Mixin that propagates execution.id and optionally filters spans."""
20+
21+
_settings: UiPathTraceSettings | None = None
22+
23+
def on_start(self, span: Span, parent_context: context_api.Context | None = None):
1824
"""Called when a span is started."""
19-
parent_span: Optional[Span]
25+
parent_span: Span | None
2026
if parent_context:
2127
parent_span = cast(Span, trace.get_current_span(parent_context))
2228
else:
@@ -27,17 +33,42 @@ def on_start(
2733
if execution_id:
2834
span.set_attribute("execution.id", execution_id)
2935

36+
def on_end(self, span: ReadableSpan):
37+
"""Called when a span ends. Filters before delegating to parent."""
38+
span_filter = self._settings.span_filter if self._settings else None
39+
if span_filter is None or span_filter(span):
40+
parent = cast(SpanProcessor, super())
41+
parent.on_end(span)
42+
3043

3144
class UiPathExecutionBatchTraceProcessor(
3245
UiPathExecutionTraceProcessorMixin, BatchSpanProcessor
3346
):
34-
"""Batch span processor that propagates execution.id."""
47+
"""Batch span processor that propagates execution.id and optionally filters."""
48+
49+
def __init__(
50+
self,
51+
span_exporter: SpanExporter,
52+
settings: UiPathTraceSettings | None = None,
53+
):
54+
"""Initialize the batch trace processor."""
55+
super().__init__(span_exporter)
56+
self._settings = settings
3557

3658

3759
class UiPathExecutionSimpleTraceProcessor(
3860
UiPathExecutionTraceProcessorMixin, SimpleSpanProcessor
3961
):
40-
"""Simple span processor that propagates execution.id."""
62+
"""Simple span processor that propagates execution.id and optionally filters."""
63+
64+
def __init__(
65+
self,
66+
span_exporter: SpanExporter,
67+
settings: UiPathTraceSettings | None = None,
68+
):
69+
"""Initialize the simple trace processor."""
70+
super().__init__(span_exporter)
71+
self._settings = settings
4172

4273

4374
__all__ = [

src/uipath/core/tracing/trace_manager.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
UiPathExecutionBatchTraceProcessor,
1616
UiPathExecutionSimpleTraceProcessor,
1717
)
18+
from uipath.core.tracing.types import UiPathTraceSettings
1819

1920

2021
class UiPathTraceManager:
@@ -40,13 +41,22 @@ def add_span_exporter(
4041
self,
4142
span_exporter: SpanExporter,
4243
batch: bool = True,
44+
settings: UiPathTraceSettings | None = None,
4345
) -> UiPathTraceManager:
44-
"""Add a span processor to the tracer provider."""
46+
"""Add a span exporter to the tracer provider.
47+
48+
Args:
49+
span_exporter: The exporter to add.
50+
batch: Whether to use batch processing (default: True).
51+
settings: Optional trace settings for filtering, etc.
52+
"""
4553
span_processor: SpanProcessor
4654
if batch:
47-
span_processor = UiPathExecutionBatchTraceProcessor(span_exporter)
55+
span_processor = UiPathExecutionBatchTraceProcessor(span_exporter, settings)
4856
else:
49-
span_processor = UiPathExecutionSimpleTraceProcessor(span_exporter)
57+
span_processor = UiPathExecutionSimpleTraceProcessor(
58+
span_exporter, settings
59+
)
5060
self.tracer_span_processors.append(span_processor)
5161
self.tracer_provider.add_span_processor(span_processor)
5262
return self

src/uipath/core/tracing/types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Tracing types for UiPath SDK."""
2+
3+
from typing import Callable
4+
5+
from opentelemetry.sdk.trace import ReadableSpan
6+
from pydantic import BaseModel
7+
8+
9+
class UiPathTraceSettings(BaseModel):
10+
"""Trace settings for UiPath SDK."""
11+
12+
model_config = {"arbitrary_types_allowed": True} # Needed for Callable
13+
14+
span_filter: Callable[[ReadableSpan], bool] | None = None

uv.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)