-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TT-9916] Add current semantic convention attributes to spans for GQL
- Loading branch information
1 parent
13caf59
commit 2e5d084
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package semconv | ||
|
||
import ( | ||
"github.com/TykTechnologies/opentelemetry/trace" | ||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
const ( | ||
// GraphQLOperationPrefix is the base prefix for all the GraphQL operation attributes | ||
GraphQLOperationPrefix = "operation." | ||
) | ||
|
||
const ( | ||
// GraphQLOperationNameKey represents the name of the operation being executed. | ||
GraphQLOperationNameKey = attribute.Key(GraphQLOperationPrefix + "name") | ||
|
||
// GraphQLOperationTypeKey The type of the operation being executed. | ||
GraphQLOperationTypeKey = attribute.Key(GraphQLOperationPrefix + "type") | ||
) | ||
|
||
const ( | ||
// GraphQLDocumentKey represents The GraphQL document being executed. | ||
GraphQLDocumentKey = attribute.Key("document") | ||
) | ||
|
||
// GraphQLOperationName returns an attribute KeyValue conforming to the | ||
// "operation.name" semantic convention. | ||
func GraphQLOperationName(name string) trace.Attribute { | ||
return GraphQLOperationNameKey.String(name) | ||
} | ||
|
||
// GraphQLOperationType returns an attribute KeyValue conforming to the | ||
// "operation.type" semantic convention. | ||
func GraphQLOperationType(operationType string) trace.Attribute { | ||
return GraphQLOperationTypeKey.String(operationType) | ||
} | ||
|
||
// GraphQLDocument returns an attribute KeyValue conforming to the | ||
// "document" semantic convention. | ||
func GraphQLDocument(document string) trace.Attribute { | ||
return GraphQLDocumentKey.String(document) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package semconv | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
func TestGraphQLOperationName(t *testing.T) { | ||
name := "MyQuery" | ||
expectedAttribute := attribute.Key(GraphQLOperationPrefix + "name").String(name) | ||
actualAttribute := GraphQLOperationName(name) | ||
assert.Equal(t, expectedAttribute, actualAttribute, "The attributes should be equal") | ||
} | ||
|
||
func TestGraphQLOperationType(t *testing.T) { | ||
operationType := "mutation" | ||
expectedAttribute := attribute.Key(GraphQLOperationPrefix + "type").String(operationType) | ||
actualAttribute := GraphQLOperationType(operationType) | ||
assert.Equal(t, expectedAttribute, actualAttribute, "The attributes should be equal") | ||
} | ||
|
||
func TestGraphQLDocument(t *testing.T) { | ||
document := "query{}" | ||
expectedAttribute := GraphQLDocumentKey.String(document) | ||
actualAttribute := GraphQLDocument(document) | ||
assert.Equal(t, expectedAttribute, actualAttribute, "The attributes should be equal") | ||
} |