Skip to content

Commit

Permalink
[Traceql] Add support for event timestamp (#3908)
Browse files Browse the repository at this point in the history
* add event start time

* add event:timeSinceStart

* changelog

* missed one test

* more test
  • Loading branch information
ie-pham authored Jul 25, 2024
1 parent 3ad6f9d commit d0f0a5f
Show file tree
Hide file tree
Showing 18 changed files with 643 additions and 495 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [FEATURE] TraceQL support for link attribute querying [#3814](https://github.com/grafana/tempo/pull/3814) (@ie-pham)
* [FEATURE] TraceQL support for event scope and event:name intrinsic [#3708](https://github.com/grafana/tempo/pull/3708) (@stoewer)
* [FEATURE] TraecQL support for event attributes [#3708](https://github.com/grafana/tempo/pull/3748) (@ie-pham)
* [FEATURE] TraceQL support for event:timeSinceStart [#3908](https://github.com/grafana/tempo/pull/3908) (@ie-pham)
* [FEATURE] Autocomplete support for events and links [#3846](https://github.com/grafana/tempo/pull/3846) (@ie-pham)
* [FEATURE] Flush and query RF1 blocks for TraceQL metric queries [#3628](https://github.com/grafana/tempo/pull/3628) [#3691](https://github.com/grafana/tempo/pull/3691) [#3723](https://github.com/grafana/tempo/pull/3723) (@mapno)
* [FEATURE] Add new compare() metrics function [#3695](https://github.com/grafana/tempo/pull/3695) (@mdisibio)
Expand Down
1 change: 1 addition & 0 deletions docs/sources/tempo/traceql/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The following table shows the current available scoped intrinsic fields:
| `trace:rootService` | string | if it exists the service name of the root span in the trace | `{ trace:rootServiceName = "gateway" }`|
| `trace:id` | string | trace id using hex string | `{ trace:id = "1234567890abcde" }` |
| `event:name` | string | name of event | `{ event:name = "exception" }` |
| `event:timeSinceStart` | duration | time of event in relation to the span start time | `{ event:timeSinceStart > 2ms}` |
| `link:spanID` | string | link span id using hex string | `{ link:spanID = "0000000000000001" }` |
| `link:traceID` | string | link trace id using hex string | `{ link:traceID = "1234567890abcde" }` |

Expand Down
2 changes: 1 addition & 1 deletion integration/e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func callSearchTagsV2AndAssert(t *testing.T, svc *e2e.HTTPService, scope, query
if scope == "none" || scope == "" || scope == "intrinsic" {
expected.Scopes = append(expected.Scopes, &tempopb.SearchTagsV2Scope{
Name: "intrinsic",
Tags: []string{"duration", "event:name", "kind", "name", "rootName", "rootServiceName", "span:duration", "span:kind", "span:name", "span:status", "span:statusMessage", "status", "statusMessage", "trace:duration", "trace:rootName", "trace:rootService", "traceDuration"},
Tags: []string{"duration", "event:name", "event:timeSinceStart", "kind", "name", "rootName", "rootServiceName", "span:duration", "span:kind", "span:name", "span:status", "span:statusMessage", "status", "statusMessage", "trace:duration", "trace:rootName", "trace:rootService", "traceDuration"},
})
}
sort.Slice(expected.Scopes, func(i, j int) bool { return expected.Scopes[i].Name < expected.Scopes[j].Name })
Expand Down
2 changes: 1 addition & 1 deletion modules/ingester/instance_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func TestInstanceSearchTagsSpecialCases(t *testing.T) {
require.Equal(
t,
[]string{
"duration", "event:name", "kind", "name", "rootName", "rootServiceName",
"duration", "event:name", "event:timeSinceStart", "kind", "name", "rootName", "rootServiceName",
"span:duration", "span:kind", "span:name", "span:status", "span:statusMessage", "status", "statusMessage",
"trace:duration", "trace:rootName", "trace:rootService", "traceDuration",
},
Expand Down
1 change: 1 addition & 0 deletions pkg/search/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func GetVirtualIntrinsicValues() []string {
traceql.ScopedIntrinsicTraceRootService.String(),
traceql.ScopedIntrinsicTraceDuration.String(),
traceql.IntrinsicEventName.String(),
traceql.IntrinsicEventTimeSinceStart.String(),
/* these are technically intrinsics that can be requested, but they are not generally of interest to a user
typing a query. for simplicity and clarity we are leaving them out of autocomplete
IntrinsicNestedSetLeft
Expand Down
2 changes: 2 additions & 0 deletions pkg/traceql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ func (a Attribute) impliedType() StaticType {
return TypeKind
case IntrinsicEventName:
return TypeString
case IntrinsicEventTimeSinceStart:
return TypeDuration
case IntrinsicLinkTraceID:
return TypeString
case IntrinsicLinkSpanID:
Expand Down
41 changes: 24 additions & 17 deletions pkg/traceql/enum_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const (
IntrinsicNestedSetRight
IntrinsicNestedSetParent
IntrinsicEventName
IntrinsicEventTimeSinceStart
IntrinsicLinkSpanID
IntrinsicLinkTraceID

Expand Down Expand Up @@ -108,23 +109,25 @@ const (
)

var (
IntrinsicDurationAttribute = NewIntrinsic(IntrinsicDuration)
IntrinsicNameAttribute = NewIntrinsic(IntrinsicName)
IntrinsicStatusAttribute = NewIntrinsic(IntrinsicStatus)
IntrinsicStatusMessageAttribute = NewIntrinsic(IntrinsicStatusMessage)
IntrinsicKindAttribute = NewIntrinsic(IntrinsicKind)
IntrinsicSpanIDAttribute = NewIntrinsic(IntrinsicSpanID)
IntrinsicChildCountAttribute = NewIntrinsic(IntrinsicChildCount)
IntrinsicTraceIDAttribute = NewIntrinsic(IntrinsicTraceID)
IntrinsicTraceRootServiceAttribute = NewIntrinsic(IntrinsicTraceRootService)
IntrinsicTraceRootSpanAttribute = NewIntrinsic(IntrinsicTraceRootSpan)
IntrinsicTraceDurationAttribute = NewIntrinsic(IntrinsicTraceDuration)
IntrinsicSpanStartTimeAttribute = NewIntrinsic(IntrinsicSpanStartTime)
IntrinsicNestedSetLeftAttribute = NewIntrinsic(IntrinsicNestedSetLeft)
IntrinsicNestedSetRightAttribute = NewIntrinsic(IntrinsicNestedSetRight)
IntrinsicNestedSetParentAttribute = NewIntrinsic(IntrinsicNestedSetParent)
IntrinsicLinkTraceIDAttribute = NewIntrinsic(IntrinsicLinkTraceID)
IntrinsicLinkSpanIDAttribute = NewIntrinsic(IntrinsicLinkSpanID)
IntrinsicDurationAttribute = NewIntrinsic(IntrinsicDuration)
IntrinsicNameAttribute = NewIntrinsic(IntrinsicName)
IntrinsicStatusAttribute = NewIntrinsic(IntrinsicStatus)
IntrinsicStatusMessageAttribute = NewIntrinsic(IntrinsicStatusMessage)
IntrinsicKindAttribute = NewIntrinsic(IntrinsicKind)
IntrinsicSpanIDAttribute = NewIntrinsic(IntrinsicSpanID)
IntrinsicChildCountAttribute = NewIntrinsic(IntrinsicChildCount)
IntrinsicTraceIDAttribute = NewIntrinsic(IntrinsicTraceID)
IntrinsicTraceRootServiceAttribute = NewIntrinsic(IntrinsicTraceRootService)
IntrinsicTraceRootSpanAttribute = NewIntrinsic(IntrinsicTraceRootSpan)
IntrinsicTraceDurationAttribute = NewIntrinsic(IntrinsicTraceDuration)
IntrinsicSpanStartTimeAttribute = NewIntrinsic(IntrinsicSpanStartTime)
IntrinsicNestedSetLeftAttribute = NewIntrinsic(IntrinsicNestedSetLeft)
IntrinsicNestedSetRightAttribute = NewIntrinsic(IntrinsicNestedSetRight)
IntrinsicNestedSetParentAttribute = NewIntrinsic(IntrinsicNestedSetParent)
IntrinsicLinkTraceIDAttribute = NewIntrinsic(IntrinsicLinkTraceID)
IntrinsicLinkSpanIDAttribute = NewIntrinsic(IntrinsicLinkSpanID)
IntrinsicEventNameAttribute = NewIntrinsic(IntrinsicEventName)
IntrinsicEventTimeSinceStartAttribute = NewIntrinsic(IntrinsicEventTimeSinceStart)
)

func (i Intrinsic) String() string {
Expand All @@ -145,6 +148,8 @@ func (i Intrinsic) String() string {
return "childCount"
case IntrinsicEventName:
return "event:name"
case IntrinsicEventTimeSinceStart:
return "event:timeSinceStart"
case IntrinsicLinkSpanID:
return "link:spanID"
case IntrinsicLinkTraceID:
Expand Down Expand Up @@ -210,6 +215,8 @@ func intrinsicFromString(s string) Intrinsic {
return IntrinsicChildCount
case "event:name":
return IntrinsicEventName
case "event:timeSinceStart":
return IntrinsicEventTimeSinceStart
case "link:spanID":
return IntrinsicLinkSpanID
case "link:traceID":
Expand Down
2 changes: 2 additions & 0 deletions pkg/traceql/expr.y
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import (
NIL TRUE FALSE STATUS_ERROR STATUS_OK STATUS_UNSET
KIND_UNSPECIFIED KIND_INTERNAL KIND_SERVER KIND_CLIENT KIND_PRODUCER KIND_CONSUMER
IDURATION CHILDCOUNT NAME STATUS STATUS_MESSAGE PARENT KIND ROOTNAME ROOTSERVICENAME
TIMESINCESTART
ROOTSERVICE TRACEDURATION NESTEDSETLEFT NESTEDSETRIGHT NESTEDSETPARENT ID TRACE_ID SPAN_ID
PARENT_DOT RESOURCE_DOT SPAN_DOT TRACE_COLON SPAN_COLON EVENT_COLON EVENT_DOT LINK_COLON LINK_DOT
COUNT AVG MAX MIN SUM
Expand Down Expand Up @@ -406,6 +407,7 @@ scopedIntrinsicField:
| SPAN_COLON ID { $$ = NewIntrinsic(IntrinsicSpanID) }
// event:
| EVENT_COLON NAME { $$ = NewIntrinsic(IntrinsicEventName) }
| EVENT_COLON TIMESINCESTART { $$ = NewIntrinsic(IntrinsicEventTimeSinceStart) }
// link:
| LINK_COLON TRACE_ID { $$ = NewIntrinsic(IntrinsicLinkTraceID) }
| LINK_COLON SPAN_ID { $$ = NewIntrinsic(IntrinsicLinkSpanID) }
Expand Down
Loading

0 comments on commit d0f0a5f

Please sign in to comment.