Go hooks are currently available with the Odigos Enterprise plan.
Contact us for more information.
Contact us for more information.
Trace and Span Context
The following hooks allow you to access the current trace and span IDs in your application. This is useful when you need to correlate your application’s logs with the distributed traces generated by Odigos. These functions are available in thegithub.com/odigos-io/odigos/hooks/go
module, ie:
Get W3C Trace Context
Get Current Trace ID
Get Current Span ID
Check for zero values
The following helper functions can be used to check if the hooks returned a zero value. Zero values indicate that no trace is currently active at the call site of the hook.Gin Middleware
Odigos can instrument Gin middleware using a provided wrapper handler fromgithub.com/odigos-io/odigos/hooks/go/gin
:
LoggerMiddleware
and AuthMiddleware
:
odigos.gin.middleware.func
.
In the above example, these are main.main.LoggerMiddleware.func2
and main.main.AuthMiddleware.func3
.
Example Application
First, follow the steps in the Quickstart to set up a Kind cluster, install Jaeger, and install Odigos (note: Go hooks are only available with an enterprise token, which you can set in this walkthrough by installing with--onprem-token=<YOUR_TOKEN>
).
Next create a folder for your sample app and initialize the Go module:
net/http
that demonstrates how to use the Go hooks:
Dockerfile
:
deployment.yaml
:
IMAGE_TAG
environment variable you defined above:
kubectl port-forward
:
localhost:16686
in your browser.
Troubleshooting
If you’re not seeing trace or span IDs:- Make sure Odigos is properly configured and running
- Verify that your application is being instrumented by Odigos
- Check that you’ve initialized the hooks correctly
- Ensure your application is receiving requests that are part of a trace