|
6 | 6 |
|
7 | 7 | import logging |
8 | 8 | from importlib.metadata import version |
| 9 | +from typing import Any |
9 | 10 |
|
10 | 11 | import opentelemetry.metrics as metrics_api |
11 | 12 | import opentelemetry.sdk.metrics as metrics_sdk |
@@ -118,22 +119,46 @@ def _initialize_tracer(self) -> None: |
118 | 119 | ) |
119 | 120 | ) |
120 | 121 |
|
121 | | - def setup_console_exporter(self) -> "StrandsTelemetry": |
122 | | - """Set up console exporter for the tracer provider.""" |
| 122 | + def setup_console_exporter(self, **kwargs: Any) -> "StrandsTelemetry": |
| 123 | + """Set up console exporter for the tracer provider. |
| 124 | +
|
| 125 | + Args: |
| 126 | + **kwargs: Optional keyword arguments passed directly to |
| 127 | + OpenTelemetry's ConsoleSpanExporter initializer. |
| 128 | +
|
| 129 | + Returns: |
| 130 | + self: Enables method chaining. |
| 131 | +
|
| 132 | + This method configures a SimpleSpanProcessor with a ConsoleSpanExporter, |
| 133 | + allowing trace data to be output to the console. Any additional keyword |
| 134 | + arguments provided will be forwarded to the ConsoleSpanExporter. |
| 135 | + """ |
123 | 136 | try: |
124 | 137 | logger.info("Enabling console export") |
125 | | - console_processor = SimpleSpanProcessor(ConsoleSpanExporter()) |
| 138 | + console_processor = SimpleSpanProcessor(ConsoleSpanExporter(**kwargs)) |
126 | 139 | self.tracer_provider.add_span_processor(console_processor) |
127 | 140 | except Exception as e: |
128 | 141 | logger.exception("error=<%s> | Failed to configure console exporter", e) |
129 | 142 | return self |
130 | 143 |
|
131 | | - def setup_otlp_exporter(self) -> "StrandsTelemetry": |
132 | | - """Set up OTLP exporter for the tracer provider.""" |
| 144 | + def setup_otlp_exporter(self, **kwargs: Any) -> "StrandsTelemetry": |
| 145 | + """Set up OTLP exporter for the tracer provider. |
| 146 | +
|
| 147 | + Args: |
| 148 | + **kwargs: Optional keyword arguments passed directly to |
| 149 | + OpenTelemetry's OTLPSpanExporter initializer. |
| 150 | +
|
| 151 | + Returns: |
| 152 | + self: Enables method chaining. |
| 153 | +
|
| 154 | + This method configures a BatchSpanProcessor with an OTLPSpanExporter, |
| 155 | + allowing trace data to be exported to an OTLP endpoint. Any additional |
| 156 | + keyword arguments provided will be forwarded to the OTLPSpanExporter. |
| 157 | + """ |
133 | 158 | from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter |
134 | 159 |
|
135 | 160 | try: |
136 | | - otlp_exporter = OTLPSpanExporter() |
| 161 | + otlp_exporter = OTLPSpanExporter(**kwargs) |
137 | 162 | batch_processor = BatchSpanProcessor(otlp_exporter) |
138 | 163 | self.tracer_provider.add_span_processor(batch_processor) |
139 | 164 | logger.info("OTLP exporter configured") |
|
0 commit comments