OpenTelemetry Action

By default, the OpenTelemetry trace action is turned off and does not send trace data to the address configured in the otel exporter. The OpenResty Edge has two built-in actions: enable the trace feature and set the span name. These two actions and the startup condition can be flexibly combined to enable the trace function. You can also use EdgeLang for more granular control.

Enable trace

By default, otel trace is disabled, use this action to enable trace.

Set the span name

By default, the span name is the URI of the request, you can set the span name with this action.

Cases

Enable tracing based on URI

If trace is enabled for all requests, a lot of trace information will be generated. Since we usually only focus on specific requests, we can dynamically enable trace as needed, e.g., if we find that an API interface has high latency, we enable trace with the following configuration.

Ratio-based tracing

In day-to-day operations, we don’t have a specific monitoring goal and don’t want to enable trace for all requests, so it’s appropriate to use a ratio to enable it.

The EdgeLang code used in the above example:

random-hit(0.05) =>
    enable-otel-trace();

We can also use EdgeLang to implement arbitrarily complex enablement controls. For example, let’s say we want to monitor a newly launched app that sends HTTP requests with a version field, while still maintaining daily monitoring. Then we can use EedgeLang as follows:

edge random-hit(0.05); req-header(“app_version”) eq “6.0” => enable-otel-trace();