honeyhive.tracer.processing.otlp_session
Optimized HTTP session factory for OpenTelemetry OTLP exports.
This module provides utilities for creating high-performance HTTP sessions specifically optimized for OTLP (OpenTelemetry Protocol) span exports. The sessions feature enhanced connection pooling, intelligent retry strategies, and configurations tuned for telemetry workloads.
Key optimizations: - Connection pooling with configurable pool sizes - Retry strategies for transient network failures - Non-blocking pool behavior for high throughput - Optimized timeouts for telemetry data
OTLPSessionConfig
Bases: BaseModel
Configuration for optimized OTLP HTTP sessions.
This class encapsulates all configuration options for creating high-performance HTTP sessions for OTLP exports.
Source code in src/honeyhive/tracer/processing/otlp_session.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
pool_connections
class-attribute
instance-attribute
pool_connections: int = Field(
default=10,
description="Number of connection pools to cache",
ge=1,
le=100,
)
pool_maxsize
class-attribute
instance-attribute
pool_maxsize: int = Field(
default=20,
description="Maximum connections per pool",
ge=1,
le=200,
)
max_retries
class-attribute
instance-attribute
max_retries: int = Field(
default=3,
description="Maximum retry attempts for failed requests",
ge=0,
le=20,
)
pool_block
class-attribute
instance-attribute
pool_block: bool = Field(
default=False,
description="Whether to block when pool is full",
)
timeout
class-attribute
instance-attribute
timeout: Optional[float] = Field(
default=30.0,
description="Request timeout in seconds",
gt=0.0,
le=600.0,
)
backoff_factor
class-attribute
instance-attribute
backoff_factor: float = Field(
default=0.5,
description="Backoff factor for retry delays",
ge=0.0,
le=10.0,
)
retry_status_codes
class-attribute
instance-attribute
retry_status_codes: List[int] = Field(
default_factory=lambda: [429, 500, 502, 503, 504],
description="HTTP status codes to retry",
)
validate_pool_maxsize
classmethod
Ensure pool_maxsize is at least as large as pool_connections.
Note: This validation logic is intentionally duplicated between OTLPSessionConfig and EnvironmentProfile classes as both need the same pool size validation constraints.
Source code in src/honeyhive/tracer/processing/otlp_session.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
validate_retry_status_codes
classmethod
Validate HTTP status codes are in valid range.
Source code in src/honeyhive/tracer/processing/otlp_session.py
107 108 109 110 111 112 113 114 115 116 | |
create_optimized_otlp_session
create_optimized_otlp_session(
config: Optional[OTLPSessionConfig] = None,
tracer_instance: Optional[Any] = None,
) -> Session
Create optimized requests.Session for OTLP exports.
This function creates a high-performance HTTP session specifically optimized for OpenTelemetry OTLP span exports. The session features:
- Enhanced connection pooling for reduced connection overhead
- Intelligent retry strategy for transient network failures
- Optimized timeouts and backoff strategies for telemetry workloads
- Non-blocking pool behavior for high-throughput scenarios
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[OTLPSessionConfig]
|
Optional session configuration (uses defaults if None) |
None
|
tracer_instance
|
Optional[Any]
|
Optional tracer instance for logging context |
None
|
Returns:
| Type | Description |
|---|---|
Session
|
Optimized requests.Session configured for OTLP exports |
Example
config = OTLPSessionConfig(pool_maxsize=30, max_retries=5) session = create_optimized_otlp_session(config, tracer_instance)
Use session with OTLPSpanExporter
exporter = OTLPSpanExporter(endpoint="...", session=session)
Source code in src/honeyhive/tracer/processing/otlp_session.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
get_session_stats
Get connection pool statistics from a requests session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The requests.Session to analyze |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary containing pool statistics and configuration |
Source code in src/honeyhive/tracer/processing/otlp_session.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
create_dynamic_otlp_config
create_dynamic_otlp_config(
tracer_instance: Optional[Any] = None,
scenario: str = "default",
**overrides: Any
) -> OTLPSessionConfig
Create fully dynamic OTLP session configuration based on environment analysis.
This function uses pure dynamic logic to determine optimal configuration values based on actual environment conditions, resource constraints, and tracer settings. NO hardcoded values - everything calculated from real conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracer_instance
|
Optional[Any]
|
Optional tracer instance for dynamic configuration |
None
|
scenario
|
str
|
Configuration scenario hint (used for dynamic adjustments) |
'default'
|
**overrides
|
Any
|
Explicit configuration overrides |
{}
|
Returns:
| Type | Description |
|---|---|
OTLPSessionConfig
|
Dynamically configured OTLPSessionConfig based on actual environment |
Source code in src/honeyhive/tracer/processing/otlp_session.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
get_default_otlp_config
get_default_otlp_config(
tracer_instance: Optional[Any] = None,
) -> OTLPSessionConfig
Get default OTLP configuration with dynamic adjustments.
Source code in src/honeyhive/tracer/processing/otlp_session.py
532 533 534 | |
get_high_volume_otlp_config
get_high_volume_otlp_config(
tracer_instance: Optional[Any] = None,
) -> OTLPSessionConfig
Get high-volume OTLP configuration with dynamic adjustments.
Source code in src/honeyhive/tracer/processing/otlp_session.py
537 538 539 540 541 | |
get_low_latency_otlp_config
get_low_latency_otlp_config(
tracer_instance: Optional[Any] = None,
) -> OTLPSessionConfig
Get low-latency OTLP configuration with dynamic adjustments.
Source code in src/honeyhive/tracer/processing/otlp_session.py
544 545 546 547 548 | |