0
# OpenTelemetry OTLP Exporter
1
2
A convenient meta-package that provides all supported OpenTelemetry Collector Exporters for Python applications. This package acts as an umbrella installation that includes both `opentelemetry-exporter-otlp-proto-grpc` and `opentelemetry-exporter-otlp-proto-http` dependencies, enabling developers to easily install and use OTLP (OpenTelemetry Protocol) exporters for sending telemetry data (traces, metrics, and logs) to OpenTelemetry Collector endpoints.
3
4
**Important**: This package registers only **gRPC exporters** as entry points for the OpenTelemetry SDK. HTTP exporters are available through direct imports but are not registered as SDK entry points.
5
6
## Package Information
7
8
- **Package Name**: opentelemetry-exporter-otlp
9
- **Language**: Python
10
- **Installation**: `pip install opentelemetry-exporter-otlp`
11
12
## Core Imports
13
14
### gRPC Exporters
15
16
```python
17
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
18
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
19
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter
20
```
21
22
### HTTP Exporters
23
24
```python
25
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
26
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
27
from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter
28
```
29
30
Note: Both gRPC and HTTP exporters use the same class names. Import from the appropriate module based on your protocol preference.
31
32
## Basic Usage
33
34
### Using gRPC Exporters
35
36
```python
37
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
38
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
39
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter
40
41
# Create exporters with default settings (localhost:4317)
42
span_exporter = OTLPSpanExporter()
43
metric_exporter = OTLPMetricExporter()
44
log_exporter = OTLPLogExporter()
45
46
# Create exporters with custom endpoint
47
span_exporter = OTLPSpanExporter(
48
endpoint="https://my-collector:4317",
49
headers={"api-key": "your-api-key"}
50
)
51
```
52
53
### Using HTTP Exporters
54
55
```python
56
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
57
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter
58
from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter
59
60
# Create exporters with default settings (localhost:4318)
61
span_exporter = OTLPSpanExporter()
62
metric_exporter = OTLPMetricExporter()
63
log_exporter = OTLPLogExporter()
64
65
# Create exporters with custom endpoint and SSL
66
span_exporter = OTLPSpanExporter(
67
endpoint="https://my-collector:4318/v1/traces",
68
headers={"Authorization": "Bearer token"},
69
certificate_file="/path/to/cert.pem"
70
)
71
```
72
73
## Architecture
74
75
This meta-package aggregates functionality from two main dependencies:
76
- **opentelemetry-exporter-otlp-proto-grpc**: Provides gRPC-based exporters
77
- **opentelemetry-exporter-otlp-proto-http**: Provides HTTP-based exporters
78
79
Each protocol supports three types of exporters:
80
- **Span Exporters**: Export distributed tracing data
81
- **Metric Exporters**: Export metrics and measurements
82
- **Log Exporters**: Export structured log data
83
84
### Entry Points Registration
85
86
The package registers the following entry points for OpenTelemetry SDK integration:
87
- `opentelemetry_traces_exporter.otlp`: gRPC OTLPSpanExporter
88
- `opentelemetry_metrics_exporter.otlp`: gRPC OTLPMetricExporter
89
- `opentelemetry_logs_exporter.otlp`: gRPC OTLPLogExporter
90
91
**Note**: Only gRPC exporters are registered as entry points. HTTP exporters must be imported and configured directly.
92
93
All exporters implement the OpenTelemetry Protocol (OTLP) specification and support environment variable configuration following OpenTelemetry standards.
94
95
## Capabilities
96
97
### gRPC Protocol Exporters
98
99
OTLP exporters using gRPC protocol with protobuf serialization. These exporters provide efficient binary protocol communication with OpenTelemetry Collector endpoints.
100
101
```python { .api }
102
class OTLPSpanExporter:
103
def __init__(self, endpoint=None, insecure=None, credentials=None, headers=None, timeout=None, compression=None, channel_options=None): ...
104
def export(self, spans): ...
105
def shutdown(self): ...
106
def force_flush(self): ...
107
108
class OTLPMetricExporter:
109
def __init__(self, endpoint=None, insecure=None, credentials=None, headers=None, timeout=None, compression=None, preferred_temporality=None, preferred_aggregation=None, max_export_batch_size=None, channel_options=None): ...
110
def export(self, metrics): ...
111
def shutdown(self): ...
112
def force_flush(self): ...
113
114
class OTLPLogExporter:
115
def __init__(self, endpoint=None, insecure=None, credentials=None, headers=None, timeout=None, compression=None, channel_options=None): ...
116
def export(self, logs): ...
117
def shutdown(self): ...
118
def force_flush(self): ...
119
```
120
121
[gRPC Exporters](./grpc-exporters.md)
122
123
### HTTP Protocol Exporters
124
125
OTLP exporters using HTTP protocol with protobuf serialization. These exporters provide HTTP-based communication with OpenTelemetry Collector endpoints, suitable for environments where HTTP is preferred over gRPC.
126
127
```python { .api }
128
class OTLPSpanExporter:
129
def __init__(self, endpoint=None, certificate_file=None, client_key_file=None, client_certificate_file=None, headers=None, timeout=None, compression=None, session=None): ...
130
def export(self, spans): ...
131
def shutdown(self): ...
132
def force_flush(self): ...
133
134
class OTLPMetricExporter:
135
def __init__(self, endpoint=None, certificate_file=None, client_key_file=None, client_certificate_file=None, headers=None, timeout=None, compression=None, session=None, preferred_temporality=None, preferred_aggregation=None): ...
136
def export(self, metrics): ...
137
def shutdown(self): ...
138
def force_flush(self): ...
139
140
class OTLPLogExporter:
141
def __init__(self, endpoint=None, certificate_file=None, client_key_file=None, client_certificate_file=None, headers=None, timeout=None, compression=None, session=None): ...
142
def export(self, logs): ...
143
def shutdown(self): ...
144
def force_flush(self): ...
145
```
146
147
[HTTP Exporters](./http-exporters.md)
148
149
## Environment Variables
150
151
All exporters support configuration via OpenTelemetry standard environment variables:
152
153
- **General**: `OTEL_EXPORTER_OTLP_*` (applies to all exporters)
154
- **Traces**: `OTEL_EXPORTER_OTLP_TRACES_*` (trace-specific settings)
155
- **Metrics**: `OTEL_EXPORTER_OTLP_METRICS_*` (metric-specific settings)
156
- **Logs**: `OTEL_EXPORTER_OTLP_LOGS_*` (log-specific settings)
157
158
Common environment variables include:
159
- `OTEL_EXPORTER_OTLP_ENDPOINT`: Base collector endpoint
160
- `OTEL_EXPORTER_OTLP_HEADERS`: Authentication headers
161
- `OTEL_EXPORTER_OTLP_TIMEOUT`: Export timeout
162
- `OTEL_EXPORTER_OTLP_COMPRESSION`: Compression algorithm
163
164
## Required Imports
165
166
For proper type annotations and usage, import the following when using the exporters:
167
168
```python
169
# Return types
170
from opentelemetry.sdk.trace.export import SpanExportResult
171
from opentelemetry.sdk.metrics.export import MetricExportResult
172
from opentelemetry.sdk._logs._internal.export import LogExportResult
173
174
# gRPC types
175
import grpc
176
from grpc import ChannelCredentials, Compression as GrpcCompression
177
178
# HTTP types
179
import requests
180
from opentelemetry.exporter.otlp.proto.http import Compression
181
```
182
183
## Types
184
185
```python { .api }
186
# HTTP Compression enumeration
187
class Compression:
188
NoCompression = "none"
189
Deflate = "deflate"
190
Gzip = "gzip"
191
192
# Export result types
193
class SpanExportResult:
194
"""Result of span export operation."""
195
SUCCESS = 0
196
FAILURE = 1
197
198
class MetricExportResult:
199
"""Result of metric export operation."""
200
SUCCESS = 0
201
FAILURE = 1
202
203
class LogExportResult:
204
"""Result of log export operation."""
205
SUCCESS = 0
206
FAILURE = 1
207
```