ivcap-lambda 0.8.3__tar.gz → 0.8.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ivcap-lambda
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: Helper functions for building lambda-style services on the IVCAP platform
5
5
  License-File: AUTHORS.md
6
6
  License-File: LICENSE
@@ -17,6 +17,7 @@ from ivcap_service import (
17
17
  Service,
18
18
  SidecarReporter,
19
19
  getLogger,
20
+ init_openobserve_from_env,
20
21
  otel_instrument,
21
22
  print_tool_definition,
22
23
  service_log_config,
@@ -66,7 +67,8 @@ def start_lambda_server(
66
67
  logger (Logger): optional logger instance; defaults to getLogger("app")
67
68
  custom_args (Optional[Callable[[argparse.ArgumentParser], argparse.Namespace]], optional): callback to add extra CLI arguments. Defaults to None.
68
69
  run_opts (Optional[Dict[str, Any]], optional): extra options forwarded to uvicorn.Config. Defaults to None.
69
- with_telemetry: (Optional[bool]): Instantiate or block use of OpenTelemetry tracing
70
+ with_telemetry: (Optional[bool]): Tri-state control of OpenTelemetry
71
+ instrumentation. CLI flags take precedence over this parameter.
70
72
  """
71
73
  if len(tools) == 0:
72
74
  raise ValueError(
@@ -94,8 +96,16 @@ def start_lambda_server(
94
96
  parser.add_argument(
95
97
  "--port", type=int, default=os.environ.get("PORT", "8090"), help="Port number"
96
98
  )
97
- parser.add_argument(
98
- "--with-telemetry", action="store_true", help="Initialise OpenTelemetry"
99
+ telemetry_group = parser.add_mutually_exclusive_group()
100
+ telemetry_group.add_argument(
101
+ "--with-telemetry",
102
+ action="store_true",
103
+ help="Force-enable OpenTelemetry instrumentation",
104
+ )
105
+ telemetry_group.add_argument(
106
+ "--without-telemetry",
107
+ action="store_true",
108
+ help="Force-disable OpenTelemetry instrumentation",
99
109
  )
100
110
  parser.add_argument("--with-mcp", action="store_true", help="Add an MCP endpoint")
101
111
  parser.add_argument(
@@ -187,7 +197,21 @@ def start_lambda_server(
187
197
  f"{title} - {os.getenv('VERSION')} - v{get_version()}|v{get_service_version()}"
188
198
  )
189
199
 
190
- # print(f">>>> OTEL_EXPORTER_OTLP_ENDPOINT: {os.environ.get('OTEL_EXPORTER_OTLP_ENDPOINT')}")
200
+ try:
201
+ init_openobserve_from_env(
202
+ logger=logger,
203
+ service_name=service.name,
204
+ service_version=service.version,
205
+ )
206
+ except Exception as exc:
207
+ logger.warning("OpenTelemetry initialization failed: %s", exc)
208
+
209
+ effective_with_telemetry = with_telemetry
210
+ if getattr(args, "without_telemetry", False):
211
+ effective_with_telemetry = False
212
+ elif getattr(args, "with_telemetry", False):
213
+ effective_with_telemetry = True
214
+
191
215
  set_event_reporter_factory(SidecarReporter) # type: ignore[arg-type]
192
216
 
193
217
  def get_context():
@@ -206,7 +230,7 @@ def start_lambda_server(
206
230
  # instrumented the same way as for the HTTP server.
207
231
  from .mcp import run_mcp_stdio
208
232
 
209
- otel_instrument(with_telemetry, None, logger)
233
+ otel_instrument(effective_with_telemetry, None, logger)
210
234
  run_mcp_stdio(service.name, app.version)
211
235
  return
212
236
 
@@ -224,7 +248,9 @@ def start_lambda_server(
224
248
  register_mcp(app, "/mcp")
225
249
 
226
250
  otel_instrument(
227
- with_telemetry, lambda _: FastAPIInstrumentor.instrument_app(app), logger
251
+ effective_with_telemetry,
252
+ lambda _: FastAPIInstrumentor.instrument_app(app),
253
+ logger,
228
254
  )
229
255
 
230
256
  async def _add_version(request: Request, call_next) -> Response:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ivcap-lambda"
3
- version = "0.8.3"
3
+ version = "0.8.4"
4
4
  description = "Helper functions for building lambda-style services on the IVCAP platform"
5
5
 
6
6
  authors = ["Max Ott <max.ott@csiro.au>"]
File without changes
File without changes
File without changes