Closed Rheisen closed 1 year ago
This is the output I receive from hitting a route:
{"level":"info","ts":"2022-12-07T17:18:51.281-0500","logger":"management_service","caller":"managementsvc/management_service.go:65","msg":"/management/status","id":"2IbY0KrI8hzwMAViMwopgno8ztb","status":200,"method":"GET","path":"/management/status","ip":"127.0.0.1","user_agent":"PostmanRuntime/7.29.2","latency_ms":2}
{
"Name": "status_handler",
"SpanContext": {
"TraceID": "e7b83325a623496f6159bd1d5ad3e07d",
"SpanID": "de1831d3e4852d00",
"TraceFlags": "01",
"TraceState": "",
"Remote": false
},
"Parent": {
"TraceID": "e7b83325a623496f6159bd1d5ad3e07d",
"SpanID": "9a59ebfbcceefd4a",
"TraceFlags": "01",
"TraceState": "",
"Remote": false
},
"SpanKind": 1,
"StartTime": "0001-01-01T00:00:00Z",
"EndTime": "0001-01-01T00:00:00Z",
"Attributes": null,
"Events": null,
"Links": null,
"Status": {
"Code": "Ok",
"Description": ""
},
"DroppedAttributes": 0,
"DroppedEvents": 0,
"DroppedLinks": 0,
"ChildSpanCount": 0,
"Resource": [
{
"Key": "service.instance.id",
"Value": {
"Type": "STRING",
"Value": "2IbY0KrI8hzwMAViMwopgno8ztb"
}
},
{
"Key": "service.name",
"Value": {
"Type": "STRING",
"Value": "go_mini_build_template"
}
},
{
"Key": "telemetry.sdk.language",
"Value": {
"Type": "STRING",
"Value": "go"
}
},
{
"Key": "telemetry.sdk.name",
"Value": {
"Type": "STRING",
"Value": "opentelemetry"
}
},
{
"Key": "telemetry.sdk.version",
"Value": {
"Type": "STRING",
"Value": "1.11.2"
}
}
],
"InstrumentationLibrary": {
"Name": "management_service",
"Version": "",
"SchemaURL": ""
}
}
{
"Name": "request_log",
"SpanContext": {
"TraceID": "e7b83325a623496f6159bd1d5ad3e07d",
"SpanID": "bf6bf31a0a387cba",
"TraceFlags": "01",
"TraceState": "",
"Remote": false
},
"Parent": {
"TraceID": "e7b83325a623496f6159bd1d5ad3e07d",
"SpanID": "9a59ebfbcceefd4a",
"TraceFlags": "01",
"TraceState": "",
"Remote": false
},
"SpanKind": 1,
"StartTime": "0001-01-01T00:00:00Z",
"EndTime": "0001-01-01T00:00:00Z",
"Attributes": null,
"Events": null,
"Links": null,
"Status": {
"Code": "Unset",
"Description": ""
},
"DroppedAttributes": 0,
"DroppedEvents": 0,
"DroppedLinks": 0,
"ChildSpanCount": 0,
"Resource": [
{
"Key": "service.instance.id",
"Value": {
"Type": "STRING",
"Value": "2IbY0KrI8hzwMAViMwopgno8ztb"
}
},
{
"Key": "service.name",
"Value": {
"Type": "STRING",
"Value": "go_mini_build_template"
}
},
{
"Key": "telemetry.sdk.language",
"Value": {
"Type": "STRING",
"Value": "go"
}
},
{
"Key": "telemetry.sdk.name",
"Value": {
"Type": "STRING",
"Value": "opentelemetry"
}
},
{
"Key": "telemetry.sdk.version",
"Value": {
"Type": "STRING",
"Value": "1.11.2"
}
}
],
"InstrumentationLibrary": {
"Name": "management_service",
"Version": "",
"SchemaURL": ""
}
}
{
"Name": "request",
"SpanContext": {
"TraceID": "e7b83325a623496f6159bd1d5ad3e07d",
"SpanID": "9a59ebfbcceefd4a",
"TraceFlags": "01",
"TraceState": "",
"Remote": false
},
"Parent": {
"TraceID": "00000000000000000000000000000000",
"SpanID": "0000000000000000",
"TraceFlags": "00",
"TraceState": "",
"Remote": false
},
"SpanKind": 1,
"StartTime": "0001-01-01T00:00:00Z",
"EndTime": "0001-01-01T00:00:00Z",
"Attributes": null,
"Events": null,
"Links": null,
"Status": {
"Code": "Unset",
"Description": ""
},
"DroppedAttributes": 0,
"DroppedEvents": 0,
"DroppedLinks": 0,
"ChildSpanCount": 2,
"Resource": [
{
"Key": "service.instance.id",
"Value": {
"Type": "STRING",
"Value": "2IbY0KrI8hzwMAViMwopgno8ztb"
}
},
{
"Key": "service.name",
"Value": {
"Type": "STRING",
"Value": "go_mini_build_template"
}
},
{
"Key": "telemetry.sdk.language",
"Value": {
"Type": "STRING",
"Value": "go"
}
},
{
"Key": "telemetry.sdk.name",
"Value": {
"Type": "STRING",
"Value": "opentelemetry"
}
},
{
"Key": "telemetry.sdk.version",
"Value": {
"Type": "STRING",
"Value": "1.11.2"
}
}
],
"InstrumentationLibrary": {
"Name": "management_service",
"Version": "",
"SchemaURL": ""
}
}
It could be that you need to use otelzap.WithMinLevel(zap.InfoLevel)
to start record INFO logs.
Oh my goodness, that was it. Thank you very much @vmihailenco!
I'm trying to use otelzap as middleware for fiber, but I'm not seeing log messages provided with a span context showing up in the span output. Trace IDs also do not appear in the log message, despite the logger option being present. Also perhaps relevant, Fiber is being run with Immutable set to true.
Here is the middleware function with some additional code comments:
The span context coming from c.UserContext() also appears to be valid, as it does link parent and child spans correctly.
The logger being used in the middleware function is created by this function:
Before then, the global loggers are set up like so:
The project is using go 1.19, and these versions may be relevant:
Any help would be greatly appreciated.