Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: otelgraphql-go instrumentation #9

Merged
merged 2 commits into from
Oct 30, 2021
Merged

Conversation

gtourkas
Copy link
Collaborator

No description provided.

@gtourkas gtourkas changed the title otelgraphql-go instrumentation feat: otelgraphql-go instrumentation Oct 28, 2021
@vmihailenco
Copy link
Member

👍 Thanks for sending this. I will leave some suggestions, but I can work on them myself if you are short on time. Just let me know.

What do you think about changing the high-level API

// Before
otelgraphqlgo.NewOpenTelemetryTracer

// After
otelgraphql.NewTracer

Specifically:

  • rename otelgraphqlgo to otelgraphql since official examples use graphql as a package name (graphql "github.com/graph-gophers/graphql-go")
  • remove OpenTelemetry from API since we already have otel in the package name


type OpenTelemetryTracer struct {
Tracer oteltrace.Tracer
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenTelemetryTracer -> Tracer

I would also unexport Tracer oteltrace.Tracer field to make future changes easier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


const tracerName = "github.com/uptrace/opentelemetry-go-extra/otelgraphql-go"

func NewOpenTelemetryTracer(opts ...Option) OpenTelemetryTracer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func NewTracer(opts ...Option) *Tracer {

I suggest to return a pointer here so we can add more fields to the Tracer struct, for example, add support for metrics.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}

// stolen from otellogrus
func attrAny(key string, value interface{}) attribute.KeyValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #10 to clean this up


if len(variables) != 0 {
for name, value := range variables {
span.SetAttributes(attrAny("graphql.variables."+name, value))
Copy link
Member

@vmihailenco vmihailenco Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the attribute names, but here are some ideas

  • drop trace.operation - it looks it should be part of span name
  • make span name more Go-like, e.g. graphql.Request or graphql. + operationName
  • graphql.query probably should be db.statement until the spec has a better attribute
  • graphql.operationName could be db.operation

Though I guess it is better to not argue about this right now and tweak it in subsequent PR(s)...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graphql-go already has an opentracing Tracer implementation; this is a port of that implementation so I suggest we leave as-is for now

@vmihailenco
Copy link
Member

Overall this looks pretty good and the only important stuff is in this comment. We should be ready to merge this PR once it is addressed.

@vmihailenco vmihailenco merged commit 5cf626d into uptrace:main Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants