|
| 1 | +# Collect OpenTelemetry data from functions |
| 2 | + |
| 3 | +To collect OpenTelemetry data for functions and services on OpenFaaS Edge you can deploy an OpenTelemetry [Collector](https://opentelemetry.io/docs/collector/) as additional service. |
| 4 | + |
| 5 | +## Deploy Grafana Alloy |
| 6 | + |
| 7 | +We are going to show the configuration for [Grafana Alloy](https://grafana.com/oss/alloy-opentelemetry-collector/) it is possible to different collectors as well. |
| 8 | + |
| 9 | +Add the following to the services section in the `docker-compose.yaml`: |
| 10 | + |
| 11 | +```yaml |
| 12 | +services: |
| 13 | + alloy: |
| 14 | + image: docker.io/grafana/alloy:v1.8.2 |
| 15 | + user: "65534" |
| 16 | + command: |
| 17 | + - "alloy" |
| 18 | + - "run" |
| 19 | + - "/etc/alloy/config.alloy" |
| 20 | + - "--storage.path=/tmp/alloy" |
| 21 | + - "--server.http.listen-addr=0.0.0.0:12345" |
| 22 | + - "--server.http.ui-path-prefix=/" |
| 23 | + - "--stability.level=generally-available" |
| 24 | + volumes: |
| 25 | + - type: bind |
| 26 | + source: ./config.alloy |
| 27 | + target: /etc/alloy/config.alloy |
| 28 | + restart: always |
| 29 | + ports: |
| 30 | + - "127.0.0.1:12345:12345" |
| 31 | +``` |
| 32 | +
|
| 33 | +The `ports` section is optional and makes the Alloy UI, which is served on port `12345` accessible on the host. |
| 34 | + |
| 35 | +The Alloy configuration is bind mounted into the service. Create the Alloy configuration file at `/var/lib/faasd/config.alloy`': |
| 36 | + |
| 37 | +``` |
| 38 | +otelcol.exporter.otlp "grafanacloud" { |
| 39 | + client { |
| 40 | + endpoint = "<endpoint>" |
| 41 | + auth = otelcol.auth.basic.grafanacloud.handler |
| 42 | + } |
| 43 | +} |
| 44 | +
|
| 45 | +otelcol.auth.basic "grafanacloud" { |
| 46 | + username = "<username>" |
| 47 | + password = "<api-token>" |
| 48 | +} |
| 49 | +
|
| 50 | +otelcol.receiver.otlp "otlp_receiver" { |
| 51 | + grpc { |
| 52 | + endpoint = "0.0.0.0:4317" |
| 53 | + } |
| 54 | +
|
| 55 | + http { |
| 56 | + endpoint = "0.0.0.0:4318" |
| 57 | + } |
| 58 | +
|
| 59 | + output { |
| 60 | + traces = [otelcol.processor.batch.default.input] |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +This is an example of a basic Alloy configuration that exports traces to [Grafana Cloud](https://grafana.com/products/cloud/). You will need to modify the config to with your own Grafana Cloud Tempo service endpoint and credentials or configure an exporter for a different local or cloud backend. |
| 66 | + |
| 67 | +- The [otelcol.exporter.otlp](https://grafana.com/docs/alloy/latest/reference/components/otelcol/otelcol.exporter.otlp/) component configures an OpenTelemetry Protocol (OTLP) exporter to send data to a backend for storage. |
| 68 | + |
| 69 | +- Production-ready Alloy configurations shouldn’t send OpenTelemetry data directly to an exporter for delivery. Instead, data is usually sent to one or more processor components that perform various transformations on the data. |
| 70 | + |
| 71 | + [otelcol.processor.batch](https://grafana.com/docs/alloy/latest/reference/components/otelcol/otelcol.processor.batch/) is used to batch data before sending it to the exporter to reduce the number of network requests. |
| 72 | + |
| 73 | +- [otelcol.receiver.otlp](https://grafana.com/docs/alloy/latest/reference/components/otelcol/otelcol.receiver.otlp/) is used to configure Alloy to receive telemetry data over the network using the OpenTelemetry Protocol. In this case we allow applications to send data over either HTTP or gRPC. Both endpoints listen for traffic on all interfaces. |
| 74 | + |
| 75 | +Checkout the docs for more details on [how to configure Grafana Alloy to collect OpenTelemetry data](https://grafana.com/docs/alloy/latest/collect/opentelemetry-data/) |
| 76 | + |
| 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 | + |
| 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). |
0 commit comments