@@ -11,6 +11,7 @@ Zuplo supports logging to the following sources:
1111- Datadog (Beta)
1212- Dynatrace (Beta)
1313- New Relic (Beta)
14+ - OpenTelemetry (Beta)
1415
1516If you would like to log to a different source, reach out to support@zuplo.com
1617and we'd be happy to work with you to add a new logging plugin.
@@ -281,3 +282,90 @@ can use a tool like the
281282aggregation.
282283
283284:::
285+
286+ ### OpenTelemetry (Beta)
287+
288+ The OpenTelemetry metrics plugin sends metrics to any OpenTelemetry-compatible
289+ collector using the
290+ [ OTLP HTTP JSON format] ( https://opentelemetry.io/docs/specs/otlp/#json-protobuf-encoding ) .
291+ This allows you to integrate with a wide variety of observability backends that
292+ support OpenTelemetry, including Grafana, Jaeger, Honeycomb, and many others.
293+
294+ By default, we send all metrics to your OpenTelemetry collector. However, you
295+ have the option below to configure which metrics you want to send.
296+
297+ ``` ts
298+ import {
299+ RuntimeExtensions ,
300+ OTelMetricsPlugin ,
301+ environment ,
302+ } from " @zuplo/runtime" ;
303+
304+ export function runtimeInit(runtime : RuntimeExtensions ) {
305+ runtime .addPlugin (
306+ new OTelMetricsPlugin ({
307+ // The OTLP HTTP endpoint URL for your collector
308+ url: " https://otel-collector.example.com:4318/v1/metrics" ,
309+ // Optional headers for authentication
310+ headers: {
311+ Authorization: ` Bearer ${environment .OTEL_API_KEY } ` ,
312+ },
313+ // Resource attributes to include with all metrics
314+ attributes: {
315+ " service.name" : " my-api" ,
316+ " deployment.environment" : environment .ENVIRONMENT ?? " development" ,
317+ },
318+ metrics: {
319+ latency: true ,
320+ requestContentLength: true ,
321+ responseContentLength: true ,
322+ },
323+ // You can also choose to add additional attributes to include in the metrics
324+ include: {
325+ country: false ,
326+ httpMethod: false ,
327+ statusCode: false ,
328+ path: false ,
329+ },
330+ }),
331+ );
332+ }
333+ ```
334+
335+ The plugin uses
336+ [ OpenTelemetry semantic conventions] ( https://opentelemetry.io/docs/specs/semconv/ )
337+ for metric names and attributes:
338+
339+ | Metric | Name | Unit |
340+ | ----------------------- | -------------------------------- | ---- |
341+ | Request latency | ` http.server.request.duration ` | ms |
342+ | Request content length | ` http.server.request.body.size ` | By |
343+ | Response content length | ` http.server.response.body.size ` | By |
344+
345+ When ` include ` options are enabled, the following attributes are added:
346+
347+ | Option | Attribute |
348+ | ------------ | ----------------------------- |
349+ | ` country ` | ` client.geo.country_iso_code ` |
350+ | ` httpMethod ` | ` http.request.method ` |
351+ | ` statusCode ` | ` http.response.status_code ` |
352+ | ` path ` | ` http.route ` |
353+
354+ The above configuration applies globally for all metrics sent to your
355+ OpenTelemetry collector. If you wish to dynamically configure information for a
356+ particular ZuploContext, you can use the ` OTelMetricsPlugin ` in your code.
357+ Currently, the only configuration you can set is the attributes. The values you
358+ set here will be appended to those set globally in the ` zuplo.runtime.ts ` file.
359+
360+ ``` ts
361+ import { ZuploContext , ZuploRequest , OTelMetricsPlugin } from " @zuplo/runtime" ;
362+
363+ export default async function (request : ZuploRequest , context : ZuploContext ) {
364+ const someValue = " hello" ;
365+ OTelMetricsPlugin .setContext (context , {
366+ attributes: { " my.custom.attribute" : someValue },
367+ });
368+
369+ return " What zup?" ;
370+ }
371+ ```
0 commit comments