Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 1.0.0b4 (Unreleased)

**Features**
- Add `from_connection_string` method to instantiate exporters
([#16818](https://github.com/Azure/azure-sdk-for-python/pull/16818))

## 1.0.0b3 (2021-02-11)

Expand Down
8 changes: 4 additions & 4 deletions sdk/monitor/azure-monitor-opentelemetry-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Please find the samples linked below for demonstration as to how to authenticate

```Python
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
exporter = AzureMonitorTraceExporter(
exporter = AzureMonitorTraceExporter.from_connection_string(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
)
```
Expand Down Expand Up @@ -73,7 +73,7 @@ from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter

exporter = AzureMonitorTraceExporter(
exporter = AzureMonitorTraceExporter.from_connection_string(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
)

Expand Down Expand Up @@ -110,8 +110,8 @@ tracer = trace.get_tracer(__name__)
# This line causes your calls made with the requests library to be tracked.
RequestsInstrumentor().instrument()
span_processor = BatchExportSpanProcessor(
AzureMonitorTraceExporter(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def _span_to_envelope(self, span: Span) -> TelemetryItem:
envelope.instrumentation_key = self._instrumentation_key
return envelope

@classmethod
def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "AzureMonitorTraceExporter":
return cls(connection_string=conn_str, **kwargs)

# pylint: disable=too-many-statements
# pylint: disable=too-many-branches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
tracer = trace.get_tracer(__name__)
RequestsInstrumentor().instrument()
span_processor = BatchExportSpanProcessor(
AzureMonitorTraceExporter(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

exporter = AzureMonitorTraceExporter(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
exporter = AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)

# SpanExporter receives the spans and send them to the target location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
# azure monitor trace exporter to send telemetry to appinsights
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
span_processor = BatchExportSpanProcessor(
AzureMonitorTraceExporter(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
# azure monitor trace exporter to send telemetry to appinsights
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
span_processor = BatchExportSpanProcessor(
AzureMonitorTraceExporter(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# azure monitor trace exporter to send telemetry to appinsights
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
span_processor = BatchExportSpanProcessor(
AzureMonitorTraceExporter(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)
)
trace.get_tracer_provider().add_span_processor(span_processor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter


exporter = AzureMonitorTraceExporter(
connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
exporter = AzureMonitorTraceExporter.from_connection_string(
os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING"]
)

trace.set_tracer_provider(TracerProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def test_constructor(self):
"4321abcd-5678-4efa-8abc-1234567890ab",
)

def test_from_connection_string(self):
exporter = AzureMonitorTraceExporter.from_connection_string(
"InstrumentationKey=4321abcd-5678-4efa-8abc-1234567890ab"
)
self.assertTrue(isinstance(exporter, AzureMonitorTraceExporter))
self.assertEqual(
exporter._instrumentation_key,
"4321abcd-5678-4efa-8abc-1234567890ab",
)

def test_export_empty(self):
exporter = self._exporter
result = exporter.export([])
Expand Down