15
15
16
16
import logging
17
17
from collections .abc import Callable
18
+ from collections .abc import Mapping
19
+ from enum import Enum
20
+ from typing import Any
18
21
19
22
from nat .builder .context import ContextState
20
- from nat .observability .mixin .tagging_config_mixin import PrivacyLevel
21
- from nat .observability .processor .header_redaction_processor import HeaderRedactionProcessor
23
+ from nat .observability .processor .redaction import SpanHeaderRedactionProcessor
22
24
from nat .observability .processor .span_tagging_processor import SpanTaggingProcessor
23
25
from nat .plugins .opentelemetry .otlp_span_adapter_exporter import OTLPSpanAdapterExporter
24
26
@@ -61,11 +63,10 @@ def should_redact(auth_key: str) -> bool:
61
63
endpoint="https://api.service.com/v1/traces",
62
64
headers={"Authorization": "Bearer your-token"},
63
65
redaction_attributes=["user.email", "request.body"],
64
- redaction_header= "x-user-id",
66
+ redaction_headers=[ "x-user-id"] ,
65
67
redaction_callback=should_redact,
66
68
redaction_value="REDACTED",
67
- privacy_tag_key="privacy.level",
68
- privacy_tag_value=PrivacyLevel.HIGH,
69
+ tags={"privacy.level": PrivacyLevel.HIGH, "service.type": "sensitive"},
69
70
batch_size=50,
70
71
flush_interval=10.0
71
72
)
@@ -84,13 +85,13 @@ def __init__(
84
85
resource_attributes : dict [str , str ] | None = None ,
85
86
# Redaction args
86
87
redaction_attributes : list [str ] | None = None ,
87
- redaction_header : str | None = None ,
88
- redaction_callback : Callable [[ str ], bool ] | None = None ,
88
+ redaction_headers : list [ str ] | None = None ,
89
+ redaction_callback : Callable [..., Any ] | None = None ,
89
90
redaction_enabled : bool = False ,
90
91
force_redaction : bool = False ,
91
92
redaction_value : str = "[REDACTED]" ,
92
- privacy_tag_key : str | None = None ,
93
- privacy_tag_value : PrivacyLevel | None = None ,
93
+ redaction_tag : str | None = None ,
94
+ tags : Mapping [ str , Enum | str ] | None = None ,
94
95
# OTLPSpanExporterMixin args
95
96
endpoint : str ,
96
97
headers : dict [str , str ] | None = None ,
@@ -99,20 +100,20 @@ def __init__(
99
100
100
101
Args:
101
102
context_state: The context state for the exporter.
102
- batch_size: Number of spans to batch before exporting.
103
- flush_interval: Time in seconds between automatic batch flushes.
104
- max_queue_size: Maximum number of spans to queue.
105
- drop_on_overflow: Whether to drop spans when queue is full.
106
- shutdown_timeout: Maximum time to wait for export completion during shutdown.
103
+ batch_size: Number of spans to batch before exporting, default is 100 .
104
+ flush_interval: Time in seconds between automatic batch flushes, default is 5.0 .
105
+ max_queue_size: Maximum number of spans to queue, default is 1000 .
106
+ drop_on_overflow: Whether to drop spans when queue is full, default is False .
107
+ shutdown_timeout: Maximum time to wait for export completion during shutdown, default is 10.0 .
107
108
resource_attributes: Additional resource attributes for spans.
108
109
redaction_attributes: List of span attribute keys to redact when conditions are met.
109
- redaction_header: Header key to check for authentication/user identification.
110
- redaction_callback: Function to determine if spans should be redacted based on header value.
111
- redaction_enabled: Whether the redaction processor is enabled.
112
- force_redaction: If True, always redact regardless of header checks.
113
- redaction_value: Value to replace redacted attributes with.
114
- privacy_tag_key: Key name for the privacy level tag to add to spans.
115
- privacy_tag_value: Privacy level value to assign to spans.
110
+ redaction_headers: List of header keys to check for authentication/user identification.
111
+ redaction_callback: Function that returns true to redact spans based on header value, false otherwise .
112
+ redaction_enabled: Whether the redaction processor is enabled, default is False .
113
+ force_redaction: If True, always redact regardless of header checks, default is False .
114
+ redaction_value: Value to replace redacted attributes with, default is "[REDACTED]" .
115
+ tags: Mapping of tag keys to their values (enums or strings) to add to spans.
116
+ redaction_tag: Tag to add to spans when redaction occurs .
116
117
endpoint: The endpoint for the OTLP service.
117
118
headers: The headers for the OTLP service.
118
119
**otlp_kwargs: Additional keyword arguments for the OTLP service.
@@ -129,16 +130,14 @@ def __init__(
129
130
** otlp_kwargs )
130
131
131
132
# Insert redaction and tagging processors to the front of the processing pipeline
132
- self .add_processor (HeaderRedactionProcessor (attributes = redaction_attributes ,
133
- header = redaction_header ,
134
- callback = redaction_callback ,
135
- enabled = redaction_enabled ,
136
- force_redact = force_redaction ,
137
- redaction_value = redaction_value ),
133
+ self .add_processor (SpanHeaderRedactionProcessor (attributes = redaction_attributes or [],
134
+ headers = redaction_headers or [],
135
+ callback = redaction_callback or (lambda _ : False ),
136
+ enabled = redaction_enabled ,
137
+ force_redact = force_redaction ,
138
+ redaction_value = redaction_value ,
139
+ redaction_tag = redaction_tag ),
138
140
name = "header_redaction" ,
139
141
position = 0 )
140
142
141
- self .add_processor (SpanTaggingProcessor (tag_key = privacy_tag_key ,
142
- tag_value = privacy_tag_value .value if privacy_tag_value else None ),
143
- name = "span_privacy_tagging" ,
144
- position = 1 )
143
+ self .add_processor (SpanTaggingProcessor (tags = tags ), name = "span_sensitivity_tagging" , position = 1 )
0 commit comments