Skip to content

Commit

Permalink
Log span name when include_all_attributes is on (#1790)
Browse files Browse the repository at this point in the history
* Log span name when include_all_attributes is on

* Update CHANGELOG.md
  • Loading branch information
suraciii authored Oct 11, 2022
1 parent 9b243c7 commit 2ea4dd8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ query_frontend:
* [ENHANCEMENT] Upgrade opentelemetry-proto submodule to v0.18.0 [#1754](https://github.com/grafana/tempo/pull/1754) (@mapno)
Internal types are updated to use `scope` instead of `instrumentation_library`. This is a breaking change in trace by ID queries if JSON is requested.
* [ENHANCEMENT] Metrics generator: extract `status_message` field from spans [#1786](https://github.com/grafana/tempo/pull/1786) (@stoewer)
* [ENHANCEMENT] distributor: Log span names when `distributor.log_received_spans.include_all_attributes` is on [#1790](https://github.com/grafana/tempo/pull/1790) (@suraciii)
* [BUGFIX] Honor caching and buffering settings when finding traces by id [#1697](https://github.com/grafana/tempo/pull/1697) (@joe-elliott)
* [BUGFIX] Correctly propagate errors from the iterator layer up through the queriers [#1723](https://github.com/grafana/tempo/pull/1723) (@joe-elliott)
* [BUGFIX] Make multitenancy work with HTTP [#1781](https://github.com/grafana/tempo/pull/1781) (@gouthamve)
Expand Down
1 change: 1 addition & 0 deletions modules/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ func logSpanWithAllAttributes(s *v1.Span, logger log.Logger) {
latencySeconds := float64(s.GetEndTimeUnixNano()-s.GetStartTimeUnixNano()) / float64(time.Second.Nanoseconds())
logger = log.With(
logger,
"span_name", s.Name,
"span_duration_seconds", latencySeconds,
"span_kind", s.GetKind().String(),
"span_status", s.GetStatus().GetCode().String())
Expand Down
37 changes: 21 additions & 16 deletions modules/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func TestLogSpans(t *testing.T) {
batches: []*v1.ResourceSpans{
makeResourceSpans("test", []*v1.ScopeSpans{
makeScope(
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", nil)),
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", "Test Span", nil)),
}),
},
expectedLogsSpan: []logSpan{},
Expand All @@ -689,7 +689,7 @@ func TestLogSpans(t *testing.T) {
batches: []*v1.ResourceSpans{
makeResourceSpans("test", []*v1.ScopeSpans{
makeScope(
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", nil)),
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", "Test Span", nil)),
}),
},
expectedLogsSpan: []logSpan{
Expand All @@ -707,14 +707,14 @@ func TestLogSpans(t *testing.T) {
batches: []*v1.ResourceSpans{
makeResourceSpans("test-service", []*v1.ScopeSpans{
makeScope(
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", nil),
makeSpan("e3210a2b38097332d1fe43083ea93d29", "6c21c48da4dbd1a7", nil)),
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", "Test Span1", nil),
makeSpan("e3210a2b38097332d1fe43083ea93d29", "6c21c48da4dbd1a7", "Test Span2", nil)),
makeScope(
makeSpan("bb42ec04df789ff04b10ea5274491685", "1b3a296034f4031e", nil)),
makeSpan("bb42ec04df789ff04b10ea5274491685", "1b3a296034f4031e", "Test Span3", nil)),
}),
makeResourceSpans("test-service2", []*v1.ScopeSpans{
makeScope(
makeSpan("b1c792dea27d511c145df8402bdd793a", "56afb9fe18b6c2d6", nil)),
makeSpan("b1c792dea27d511c145df8402bdd793a", "56afb9fe18b6c2d6", "Test Span", nil)),
}),
},
expectedLogsSpan: []logSpan{
Expand Down Expand Up @@ -750,14 +750,14 @@ func TestLogSpans(t *testing.T) {
batches: []*v1.ResourceSpans{
makeResourceSpans("test-service", []*v1.ScopeSpans{
makeScope(
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", nil),
makeSpan("e3210a2b38097332d1fe43083ea93d29", "6c21c48da4dbd1a7", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR})),
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", "Test Span1", nil),
makeSpan("e3210a2b38097332d1fe43083ea93d29", "6c21c48da4dbd1a7", "Test Span2", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR})),
makeScope(
makeSpan("bb42ec04df789ff04b10ea5274491685", "1b3a296034f4031e", nil)),
makeSpan("bb42ec04df789ff04b10ea5274491685", "1b3a296034f4031e", "Test Span3", nil)),
}),
makeResourceSpans("test-service2", []*v1.ScopeSpans{
makeScope(
makeSpan("b1c792dea27d511c145df8402bdd793a", "56afb9fe18b6c2d6", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR})),
makeSpan("b1c792dea27d511c145df8402bdd793a", "56afb9fe18b6c2d6", "Test Span", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR})),
}),
},
expectedLogsSpan: []logSpan{
Expand All @@ -782,21 +782,22 @@ func TestLogSpans(t *testing.T) {
batches: []*v1.ResourceSpans{
makeResourceSpans("test-service", []*v1.ScopeSpans{
makeScope(
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", nil,
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", "Test Span1", nil,
makeAttribute("tag1", "value1")),
makeSpan("e3210a2b38097332d1fe43083ea93d29", "6c21c48da4dbd1a7", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR},
makeSpan("e3210a2b38097332d1fe43083ea93d29", "6c21c48da4dbd1a7", "Test Span2", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR},
makeAttribute("tag1", "value1"),
makeAttribute("tag2", "value2"))),
makeScope(
makeSpan("bb42ec04df789ff04b10ea5274491685", "1b3a296034f4031e", nil)),
makeSpan("bb42ec04df789ff04b10ea5274491685", "1b3a296034f4031e", "Test Span3", nil)),
}, makeAttribute("resource_attribute1", "value1")),
makeResourceSpans("test-service2", []*v1.ScopeSpans{
makeScope(
makeSpan("b1c792dea27d511c145df8402bdd793a", "56afb9fe18b6c2d6", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR})),
makeSpan("b1c792dea27d511c145df8402bdd793a", "56afb9fe18b6c2d6", "Test Span", &v1.Status{Code: v1.Status_STATUS_CODE_ERROR})),
}, makeAttribute("resource_attribute2", "value2")),
},
expectedLogsSpan: []logSpan{
{
Name: "Test Span2",
Msg: "received",
Level: "info",
TraceID: "e3210a2b38097332d1fe43083ea93d29",
Expand All @@ -809,6 +810,7 @@ func TestLogSpans(t *testing.T) {
ResourceAttribute1: "value1",
},
{
Name: "Test Span",
Msg: "received",
Level: "info",
TraceID: "b1c792dea27d511c145df8402bdd793a",
Expand All @@ -827,11 +829,12 @@ func TestLogSpans(t *testing.T) {
batches: []*v1.ResourceSpans{
makeResourceSpans("test-service", []*v1.ScopeSpans{
makeScope(
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", nil, makeAttribute("tag1", "value1"))),
makeSpan("0a0102030405060708090a0b0c0d0e0f", "dad44adc9a83b370", "Test Span", nil, makeAttribute("tag1", "value1"))),
}),
},
expectedLogsSpan: []logSpan{
{
Name: "Test Span",
Msg: "received",
Level: "info",
TraceID: "0a0102030405060708090a0b0c0d0e0f",
Expand Down Expand Up @@ -884,6 +887,7 @@ type logSpan struct {
Level string `json:"level"`
TraceID string `json:"traceid"`
SpanID string `json:"spanid"`
Name string `json:"span_name"`
SpanStatus string `json:"span_status,omitempty"`
SpanKind string `json:"span_kind,omitempty"`
SpanServiceName string `json:"span_service_name,omitempty"`
Expand All @@ -900,7 +904,7 @@ func makeAttribute(key string, value string) *v1_common.KeyValue {
}
}

func makeSpan(traceID string, spanID string, status *v1.Status, attributes ...*v1_common.KeyValue) *v1.Span {
func makeSpan(traceID string, spanID string, name string, status *v1.Status, attributes ...*v1_common.KeyValue) *v1.Span {
if status == nil {
status = &v1.Status{Code: v1.Status_STATUS_CODE_OK}
}
Expand All @@ -915,6 +919,7 @@ func makeSpan(traceID string, spanID string, status *v1.Status, attributes ...*v
}

return &v1.Span{
Name: name,
TraceId: traceIDBytes,
SpanId: spanIDBytes,
Status: status,
Expand Down

0 comments on commit 2ea4dd8

Please sign in to comment.