or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

grpc-exporters.mdhttp-exporters.mdindex.md

http-exporters.mddocs/

0

# HTTP Exporters

1

2

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 or where firewall restrictions make HTTP more accessible.

3

4

## Capabilities

5

6

### Span Exporter (HTTP)

7

8

Exports distributed tracing data using the HTTP protocol. Provides reliable HTTP-based transmission of span data to OpenTelemetry Collector endpoints with support for SSL/TLS and custom authentication.

9

10

```python { .api }

11

class OTLPSpanExporter:

12

def __init__(

13

self,

14

endpoint: str | None = None,

15

certificate_file: str | None = None,

16

client_key_file: str | None = None,

17

client_certificate_file: str | None = None,

18

headers: dict[str, str] | None = None,

19

timeout: float | None = None,

20

compression: Compression | None = None,

21

session: requests.Session | None = None

22

):

23

"""

24

Create an HTTP OTLP span exporter.

25

26

Parameters:

27

- endpoint (str, optional): Collector endpoint URL. Defaults to "http://localhost:4318/v1/traces"

28

- certificate_file (str, optional): Path to SSL certificate file for server verification

29

- client_key_file (str, optional): Path to client private key file for mutual TLS

30

- client_certificate_file (str, optional): Path to client certificate file for mutual TLS

31

- headers (dict, optional): Additional headers to send with requests

32

- timeout (int, optional): Export timeout in seconds. Defaults to 10

33

- compression (Compression, optional): HTTP compression algorithm

34

- session (requests.Session, optional): Custom requests session for connection pooling

35

36

Environment Variables:

37

- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT

38

- OTEL_EXPORTER_OTLP_TRACES_HEADERS

39

- OTEL_EXPORTER_OTLP_TRACES_TIMEOUT

40

- OTEL_EXPORTER_OTLP_TRACES_COMPRESSION

41

- OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE

42

"""

43

44

def export(self, spans) -> SpanExportResult:

45

"""Export span data to the collector."""

46

47

def shutdown(self) -> None:

48

"""Shutdown the exporter and clean up resources."""

49

50

def force_flush(self, timeout_millis: int = 30000) -> bool:

51

"""Force flush any pending spans."""

52

```

53

54

### Metric Exporter (HTTP)

55

56

Exports metrics data using the HTTP protocol. Enables HTTP-based transmission of measurement data with support for different temporality preferences and aggregation methods.

57

58

```python { .api }

59

class OTLPMetricExporter:

60

def __init__(

61

self,

62

endpoint: str = None,

63

certificate_file: str = None,

64

client_key_file: str = None,

65

client_certificate_file: str = None,

66

headers: dict = None,

67

timeout: int = None,

68

compression: Compression = None,

69

session: requests.Session = None,

70

preferred_temporality: dict = None,

71

preferred_aggregation: dict = None

72

):

73

"""

74

Create an HTTP OTLP metric exporter.

75

76

Parameters:

77

- endpoint (str, optional): Collector endpoint URL. Defaults to "http://localhost:4318/v1/metrics"

78

- certificate_file (str, optional): Path to SSL certificate file for server verification

79

- client_key_file (str, optional): Path to client private key file for mutual TLS

80

- client_certificate_file (str, optional): Path to client certificate file for mutual TLS

81

- headers (dict, optional): Additional headers to send with requests

82

- timeout (int, optional): Export timeout in seconds. Defaults to 10

83

- compression (Compression, optional): HTTP compression algorithm

84

- session (requests.Session, optional): Custom requests session for connection pooling

85

- preferred_temporality (dict, optional): Preferred temporality for metric instruments

86

- preferred_aggregation (dict, optional): Preferred aggregation for metric instruments

87

88

Environment Variables:

89

- OTEL_EXPORTER_OTLP_METRICS_ENDPOINT

90

- OTEL_EXPORTER_OTLP_METRICS_HEADERS

91

- OTEL_EXPORTER_OTLP_METRICS_TIMEOUT

92

- OTEL_EXPORTER_OTLP_METRICS_COMPRESSION

93

- OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE

94

"""

95

96

def export(self, metrics) -> MetricExportResult:

97

"""Export metric data to the collector."""

98

99

def shutdown(self) -> None:

100

"""Shutdown the exporter and clean up resources."""

101

102

def force_flush(self, timeout_millis: int = 30000) -> bool:

103

"""Force flush any pending metrics."""

104

```

105

106

### Log Exporter (HTTP)

107

108

Exports structured log data using the HTTP protocol. Provides HTTP-based transmission of log records with full OpenTelemetry context correlation and support for secure connections.

109

110

```python { .api }

111

class OTLPLogExporter:

112

def __init__(

113

self,

114

endpoint: str = None,

115

certificate_file: str = None,

116

client_key_file: str = None,

117

client_certificate_file: str = None,

118

headers: dict = None,

119

timeout: int = None,

120

compression: Compression = None,

121

session: requests.Session = None

122

):

123

"""

124

Create an HTTP OTLP log exporter.

125

126

Parameters:

127

- endpoint (str, optional): Collector endpoint URL. Defaults to "http://localhost:4318/v1/logs"

128

- certificate_file (str, optional): Path to SSL certificate file for server verification

129

- client_key_file (str, optional): Path to client private key file for mutual TLS

130

- client_certificate_file (str, optional): Path to client certificate file for mutual TLS

131

- headers (dict, optional): Additional headers to send with requests

132

- timeout (int, optional): Export timeout in seconds. Defaults to 10

133

- compression (Compression, optional): HTTP compression algorithm

134

- session (requests.Session, optional): Custom requests session for connection pooling

135

136

Environment Variables:

137

- OTEL_EXPORTER_OTLP_LOGS_ENDPOINT

138

- OTEL_EXPORTER_OTLP_LOGS_HEADERS

139

- OTEL_EXPORTER_OTLP_LOGS_TIMEOUT

140

- OTEL_EXPORTER_OTLP_LOGS_COMPRESSION

141

- OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE

142

"""

143

144

def export(self, logs) -> LogExportResult:

145

"""Export log data to the collector."""

146

147

def shutdown(self) -> None:

148

"""Shutdown the exporter and clean up resources."""

149

150

def force_flush(self, timeout_millis: int = 30000) -> bool:

151

"""Force flush any pending logs."""

152

```

153

154

## Types

155

156

### Compression Enumeration

157

158

```python { .api }

159

class Compression:

160

"""HTTP compression options for OTLP exporters."""

161

162

NoCompression = "none"

163

"""No compression applied to the request body."""

164

165

Deflate = "deflate"

166

"""Deflate compression algorithm."""

167

168

Gzip = "gzip"

169

"""Gzip compression algorithm."""

170

```

171

172

## Constants

173

174

```python { .api }

175

# Default HTTP headers for OTLP requests

176

_OTLP_HTTP_HEADERS: dict = {

177

"Content-Type": "application/x-protobuf",

178

"User-Agent": "opentelemetry-python"

179

}

180

181

# Default compression setting

182

DEFAULT_COMPRESSION: Compression = Compression.NoCompression

183

184

# Default collector endpoints

185

DEFAULT_ENDPOINT: str = "http://localhost:4318/"

186

```

187

188

## Usage Examples

189

190

### Basic HTTP Export Setup

191

192

```python

193

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

194

from opentelemetry.sdk.trace import TracerProvider

195

from opentelemetry.sdk.trace.export import BatchSpanProcessor

196

197

# Create exporter with default settings

198

exporter = OTLPSpanExporter()

199

200

# Set up tracer provider with batch processor

201

tracer_provider = TracerProvider()

202

tracer_provider.add_span_processor(BatchSpanProcessor(exporter))

203

204

# Use the tracer

205

tracer = tracer_provider.get_tracer(__name__)

206

with tracer.start_as_current_span("example-span"):

207

print("Hello, World!")

208

```

209

210

### HTTPS with Custom Headers

211

212

```python

213

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

214

from opentelemetry.exporter.otlp.proto.http import Compression

215

216

# Create exporter with HTTPS and authentication

217

exporter = OTLPSpanExporter(

218

endpoint="https://my-collector:4318/v1/traces",

219

headers={

220

"Authorization": "Bearer your-token",

221

"X-Custom-Header": "custom-value"

222

},

223

compression=Compression.Gzip,

224

timeout=30

225

)

226

```

227

228

### Mutual TLS (mTLS) Configuration

229

230

```python

231

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

232

233

# Create exporter with mutual TLS

234

exporter = OTLPSpanExporter(

235

endpoint="https://secure-collector:4318/v1/traces",

236

certificate_file="/path/to/ca-cert.pem",

237

client_certificate_file="/path/to/client-cert.pem",

238

client_key_file="/path/to/client-key.pem"

239

)

240

```

241

242

### Custom Session with Connection Pooling

243

244

```python

245

import requests

246

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

247

248

# Create custom session with connection pooling

249

session = requests.Session()

250

session.mount('https://', requests.adapters.HTTPAdapter(

251

pool_connections=10,

252

pool_maxsize=20,

253

max_retries=3

254

))

255

256

# Create exporter with custom session

257

exporter = OTLPSpanExporter(

258

endpoint="https://my-collector:4318/v1/traces",

259

session=session

260

)

261

```

262

263

### Environment Variable Configuration

264

265

```python

266

import os

267

268

# Set environment variables

269

os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = "https://collector:4318/v1/traces"

270

os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = "api-key=your-key,content-type=application/x-protobuf"

271

os.environ["OTEL_EXPORTER_OTLP_TRACES_COMPRESSION"] = "gzip"

272

os.environ["OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE"] = "/path/to/ca-cert.pem"

273

274

# Create exporter - will automatically use environment variables

275

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

276

exporter = OTLPSpanExporter()

277

```

278

279

### Multi-Signal Export Setup

280

281

```python

282

from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

283

from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter

284

from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter

285

286

# Create all three exporters with consistent configuration

287

base_config = {

288

"endpoint": "https://my-collector:4318",

289

"headers": {"Authorization": "Bearer token"},

290

"timeout": 30

291

}

292

293

# Each exporter will append the appropriate path automatically

294

span_exporter = OTLPSpanExporter(

295

endpoint=f"{base_config['endpoint']}/v1/traces",

296

headers=base_config["headers"],

297

timeout=base_config["timeout"]

298

)

299

300

metric_exporter = OTLPMetricExporter(

301

endpoint=f"{base_config['endpoint']}/v1/metrics",

302

headers=base_config["headers"],

303

timeout=base_config["timeout"]

304

)

305

306

log_exporter = OTLPLogExporter(

307

endpoint=f"{base_config['endpoint']}/v1/logs",

308

headers=base_config["headers"],

309

timeout=base_config["timeout"]

310

)

311

```