GcpCompute.Telemetry (GcpCompute v0.3.0)

Copy Markdown View Source

Telemetry events emitted by the library.

Every HTTP call to the Compute API is wrapped in a :telemetry.span/3, so you get the standard :start / :stop / :exception trio.

Events

  • [:gcp_compute, :request, :start] — measurements: %{system_time, monotonic_time}; metadata: %{method, path, project}.

  • [:gcp_compute, :request, :stop] — measurements: %{duration, monotonic_time}; metadata: %{method, path, project, result, http_status} (result is :ok or :error; http_status is present on API errors).

  • [:gcp_compute, :request, :exception] — measurements: %{duration, monotonic_time}; metadata: %{method, path, project, kind, reason, stacktrace}.

Attaching a quick logger

GcpCompute.Telemetry.attach_default_logger()
GcpCompute.Telemetry.detach_default_logger()

or wire the events into Telemetry.Metrics / your reporter of choice.

Do not log :exception metadata verbatim

The :exception event's :stacktrace (and :reason) can contain a frame holding the bearer token — Req's auth step receives {:bearer, token} as an argument. GcpCompute never raises with a token in scope on any path it controls, and GcpCompute.Error redacts :body on inspect/1, but a handler that does inspect(metadata) or ships raw stacktraces to an error tracker bypasses both. Log :kind and a classified reason, not the frames.

Summary

Functions

Attach a simple Logger handler for request stops/exceptions.

Detach the handler installed by attach_default_logger/1.

The list of telemetry events this library emits.

Functions

attach_default_logger(level \\ :debug)

@spec attach_default_logger(Logger.level()) :: :ok | {:error, :already_exists}

Attach a simple Logger handler for request stops/exceptions.

Intended for development. In production prefer Telemetry.Metrics + a reporter. Pair it with detach_default_logger/0.

detach_default_logger()

@spec detach_default_logger() :: :ok | {:error, :not_found}

Detach the handler installed by attach_default_logger/1.

Returns :ok, or {:error, :not_found} if it was never attached.

events()

@spec events() :: [[atom()]]

The list of telemetry events this library emits.