MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / initialize

Method initialize

agentops/sdk/core.py:173–233  ·  view source on GitHub ↗

Initialize the tracing core with the given configuration. Args: jwt_provider: Function that returns the current JWT token **kwargs: Configuration parameters for tracing service_name: Name of the service exporter: Custom span e

(self, jwt_provider: Optional[Callable[[], Optional[str]]] = None, **kwargs: Any)

Source from the content-addressed store, hash-verified

171 atexit.register(self.shutdown)
172
173 def initialize(self, jwt_provider: Optional[Callable[[], Optional[str]]] = None, **kwargs: Any) -> None:
174 """
175 Initialize the tracing core with the given configuration.
176
177 Args:
178 jwt_provider: Function that returns the current JWT token
179 **kwargs: Configuration parameters for tracing
180 service_name: Name of the service
181 exporter: Custom span exporter
182 processor: Custom span processor
183 exporter_endpoint: Endpoint for the span exporter
184 max_queue_size: Maximum number of spans to queue before forcing a flush
185 max_wait_time: Maximum time in milliseconds to wait before flushing
186 api_key: API key for authentication (required for authenticated exporter)
187 project_id: Project ID to include in resource attributes
188 """
189 if self._initialized:
190 return
191
192 # Store JWT provider for potential updates
193 self._jwt_provider = jwt_provider
194
195 # Set default values for required fields
196 kwargs.setdefault("service_name", "agentops")
197 kwargs.setdefault("exporter_endpoint", "https://otlp.agentops.ai/v1/traces")
198 kwargs.setdefault("metrics_endpoint", "https://otlp.agentops.ai/v1/metrics")
199 kwargs.setdefault("max_queue_size", 512)
200 kwargs.setdefault("max_wait_time", 5000)
201 kwargs.setdefault("export_flush_interval", 1000)
202
203 # Create a TracingConfig from kwargs with proper defaults
204 config: TracingConfig = {
205 "service_name": kwargs["service_name"],
206 "exporter_endpoint": kwargs["exporter_endpoint"],
207 "metrics_endpoint": kwargs["metrics_endpoint"],
208 "max_queue_size": kwargs["max_queue_size"],
209 "max_wait_time": kwargs["max_wait_time"],
210 "export_flush_interval": kwargs["export_flush_interval"],
211 "api_key": kwargs.get("api_key"),
212 "project_id": kwargs.get("project_id"),
213 }
214
215 self._config = config
216
217 # Setup telemetry using the extracted configuration
218 provider, meter_provider = setup_telemetry(
219 service_name=config["service_name"] or "",
220 project_id=config.get("project_id"),
221 exporter_endpoint=config["exporter_endpoint"],
222 metrics_endpoint=config["metrics_endpoint"],
223 max_queue_size=config["max_queue_size"],
224 max_wait_time=config["max_wait_time"],
225 export_flush_interval=config["export_flush_interval"],
226 jwt_provider=jwt_provider,
227 )
228
229 self.provider = provider
230 self._meter_provider = meter_provider

Callers 3

__init__Method · 0.80
resetMethod · 0.80

Calls 2

setup_telemetryFunction · 0.85
getMethod · 0.45

Tested by 2

__init__Method · 0.64
resetMethod · 0.64