You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/edge/open-telemetry.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -76,4 +76,4 @@ Checkout the docs for more details on [how to configure Grafana Alloy to collect
76
76
77
77
Functions and services deployed on OpenFaaS Edge can use the service name when configuring the telemetry collection endpoint e,g. `alloy:4317` or `alloy:4318`.
78
78
79
-
For more info on how to instrument and configure telemetry for functions checkout our language guides for: [Python](/languages/python/#opentelemetry-zero-code-instrumentation) or [Node.js](/languages/node/#opentelemetry-zero-code-instrumentation).
79
+
For more info on how to instrument and configure telemetry for functions checkout our language guides for: [Python](/languages/python/#opentelemetry-zero-code-instrumentation), [Node.js](/languages/node/#opentelemetry-zero-code-instrumentation) or [Go](/languages/go/#opentelemetry-instrumentation)
Copy file name to clipboardExpand all lines: docs/languages/go.md
+246Lines changed: 246 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -402,3 +402,249 @@ func Handle(w http.ResponseWriter, r *http.Request) {
402
402
}
403
403
```
404
404
405
+
## OpenTelemetry instrumentation
406
+
407
+
To instrument a Go function it is recommended to modify one of the existing Go templates. This will allow you to instrument the HTTP server and handle shutdown for the OpenTelemetry SDK properly.
408
+
409
+
There are two ways to [customise a template](/cli/templates/#how-to-customise-a-template):
410
+
411
+
- Fork the template repository and modify the template. Recommended method that allows for distribution and reuse of the template.
412
+
- Pull the template and apply patches directly in the `./template/<language_name>` directory. Good for quick iteration and experimentation with template modifications. The modified template cannot be shared and reused. Changes may get overwritten when pulling templates again.
413
+
414
+
In this example we are going to modify the [`golang-middleware` template](https://github.com/openfaas/golang-http-template).
415
+
416
+
Ensure the right packages are added in the template `go.mod`:
The `getExporters` function creates and returns a list of exporters. The configuration for the exporter is read from environment variables. This makes it easy to later configure the exporters through the `stack.yaml` file of functions that use the template.
465
+
466
+
By default we support console and OTLP over gRPC exporters but you can modify this function to create your preferred exporters with specific configuration if that is required.
-`OTEL_SERVICE_NAME` sets the name of the service associated with the telemetry and is used to identify telemetry for a specific function. It can be set to any value you want but we recommend using the clear function identifier `<fn-name>.<fn-namespace>`.
579
+
-`OTEL_TRACES_EXPORTER` specifies which tracer exporter to use. In this example traces are exported to `console` (stdout) and with `otlp` to send traces to an endpoint that accepts OTLP via gRPC.
580
+
-`OTEL_EXPORTER_OTLP_ENDPOINT` sets the endpoint where telemetry is exported to.
581
+
582
+
### Creating custom traces in the function handler
583
+
584
+
When using a modified OpenTelemetry template the global trace provider can be retrieved to add custom spans or additional instrumentation libraries in the function handler.
The function `otel.GetTracerProvider()` can be used to get the registered trace provider and create a new named tracer for the function.
641
+
642
+
To create new span with a tracer, you’ll need a handle on a `context.Context` instance. These will typically come from the request object and may already contain a parent span from an [instrumentation library](https://opentelemetry.io/docs/languages/go/libraries/).
643
+
644
+
Checkout the [OpenTelemetry docs](https://opentelemetry.io/docs/languages/go/instrumentation/) for more information on how to work with spans.
645
+
646
+
## OpenTelemetry zero-code instrumentation
647
+
648
+
The beta Release for [zero-code instrumentation](https://opentelemetry.io/docs/concepts/instrumentation/zero-code/) of Go applications [has recently been announced](https://opentelemetry.io/blog/2025/go-auto-instrumentation-beta/).
649
+
650
+
Go auto-instrumentation has not been tested with OpenFaaS functions yet. The easiest way to try it out on Kubernetes is probably by using the [Opentelemetry Operator for Kubernetes](https://opentelemetry.io/docs/platforms/kubernetes/operator/automatic/).
-`OTEL_SERVICE_NAME` sets the name of the service associated with the telemetry and is used to identify telemetry for a specific function. It can be set to any value you want be we recommend using the clear function identifier `<fn-name>.<fn-namespace>`.
445
+
-`OTEL_SERVICE_NAME` sets the name of the service associated with the telemetry and is used to identify telemetry for a specific function. It can be set to any value you want but we recommend using the clear function identifier `<fn-name>.<fn-namespace>`.
446
446
-`OTEL_TRACES_EXPORTER` specifies which tracer exporter to use. In this example traces are exported to `console` (stdout) and with `otlp`. The `otlp` option tells `opentelemetry-instrument` to send the traces to an endpoint that accepts OTLP via gRPC.
447
447
- setting `OTEL_METRICS_EXPORTER` and `OTEL_LOGS_EXPORTER` to `none` we disable the metrics and logs exporters. You can enable them if desired.
448
448
-`OTEL_EXPORTER_OTLP_ENDPOINT` sets the endpoint where telemetry is exported to.
0 commit comments