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
(NB - using the tracer pulled from the global scope this way works, but it's preferable to instantiate the tracer in the init code for the service then inject it into your method. See here for full guidance: [Open Telemetry Docs](https://opentelemetry.io/docs/instrumentation/java/manual/#:~:text=To%20create%20Spans%2C%20you%20only,set%20by%20the%20OpenTelemetry%20SDK.&text=It's%20required%20to%20call%20end,you%20want%20it%20to%20end)).
72
71
73
-
74
-
## Logging Implementation
72
+
### Logging Implementation
75
73
76
74
The existing logging library has been modified to extract the traceId from the traceparent header (if it exists) and add it to the TraceId section of the log message. This will enable log entries to be correlated with trace ids which will allow engineers to zero in on problems quickly and accurately.
77
75
78
-
79
76
The original logging library was modified in order to manage the change centrally and avoid the need for code changes across multiple applications.
80
77
78
+
## Instrumenting Go services for OT
81
79
82
-
# Instrumenting Go services for OT
83
80
The following environment variables need to be created:
NB: if this isn't done any calls to the otel service will fail silently. If you find that traces are not coming through, ensure this code is getting called.
126
129
130
+
### Instrumenting http handlers
127
131
128
-
## Instrumenting http handlers
129
132
There are a wide range of different facilities for instrumenting http calls. The simplest (taken here from dp-search-api) simply creates a new opentelemetry handler to pass to the server and attaches otelmux middlewarer to the router:
A purely middleware approach can also be taken where Alice is already in place chaining middleware. Both otelmux and otelhttp are used here to capture all requests with sufficient detail. Here you can see an example instrumentation:
206
-
```
211
+
212
+
```go
207
213
funcNew(cfgConfig) http.Handler {
208
214
router:= mux.NewRouter()
209
-
router.Use(otelmux.Middleware(cfg.OTServiceName))
210
-
middleware := []alice.Constructor{
211
-
otelhttp.NewMiddleware(cfg.OTServiceName),
215
+
router.Use(otelmux.Middleware(cfg.OTServiceName))
216
+
middleware:= []alice.Constructor{
217
+
otelhttp.NewMiddleware(cfg.OTServiceName),
212
218
...
213
-
}
214
-
newAlice := alice.New(middleware...).Then(router)
219
+
}
220
+
newAlice:= alice.New(middleware...).Then(router)
215
221
}
216
222
```
217
223
218
-
## Instrumenting http calls
224
+
### Instrumenting http calls
225
+
219
226
Outgoing service calls need to be instrumented to include the traceparent header when the handler itself is not instrumented. This can be done as follows:
The `dp-mongodb` package has been instrumented centrally as of version 3.7.0. This means that there is no need for additional instrumentation in services that import this package version or above. Make sure this version or above is imported!
244
253
254
+
### Kafka Instrumentation
245
255
246
-
## Kafka Instrumentation:
247
256
The `dp-kafka` package has also be instrumented centerally as of version 4, this requires the context to be passed in order to work:
Go http request middleware was created to extract the traceId from the traceparent header and insert into the expected place in the request context (as controlled by the RequestIdKey in the github.com/ONSdigital/dp-net/v2/request package)
0 commit comments