Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add tracing for sql#1610

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
f0ssel merged 17 commits intomainfromf0ssel/otel-sql
May 20, 2022
Merged

feat: add tracing for sql#1610

f0ssel merged 17 commits intomainfromf0ssel/otel-sql
May 20, 2022

Conversation

f0ssel
Copy link
Contributor

@f0sself0ssel commentedMay 19, 2022
edited
Loading

This adds tracing for the postgres data layer. It also continues to improve on the http tracing by using a lot more built-in functions fromsemconv.

Datadog example:
SQL -
image

HTTP -
image

dwahler reacted with eyes emoji
@f0sself0ssel marked this pull request as ready for reviewMay 19, 2022 23:43
@f0sself0ssel requested review froma team,mafredri andcoadlerMay 20, 2022 00:13

sqlDriver, err = tracing.PostgresDriver(tracerProvider, "coderd.database")
if err != nil {
logger.Warn(cmd.Context(), "failed to start postgres tracing driver", slog.Error(err))
Copy link
Member

Choose a reason for hiding this comment

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

potential bug: Iftracing.PostgresDriver encounters an error here,sqlDriver will be the empty string; I believe that would cause us to fail to connect to the DB. We should probably fall back to the original driver name in this case and degrade gracefully.

Suggested change
logger.Warn(cmd.Context(),"failed to start postgres tracing driver",slog.Error(err))
logger.Warn(cmd.Context(),"failed to start postgres tracing driver",slog.Error(err))
sqlDriver="postgres"

f0ssel reacted with thumbs up emojif0ssel reacted with heart emoji
Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Very clean, and good catch with reassigning the request context. LGTM!

span.SetAttributes(semconv.NetAttributesFromHTTPRequest("tcp", r)...)
span.SetAttributes(semconv.EndUserAttributesFromHTTPRequest(r)...)
span.SetAttributes(semconv.HTTPServerAttributesFromHTTPRequest("", route, r)...)
span.SetAttributes(semconv.HTTPRouteKey.String(route))
Copy link
Member

Choose a reason for hiding this comment

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

Nice change with thesemconv package!

f0ssel reacted with heart emoji
return driverName, nil
}

func formatPostgresSpan(ctx context.Context, op string) string {
Copy link
Member

Choose a reason for hiding this comment

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

Should we add thesql: prefix (orcoder-db:), like inhttps://pkg.go.dev/github.com/nhatthm/otelsql#readme-span-name-formatter? Wondering if it'd help with narrowing down the spans.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm just copying the format I've seen before with other database tracing tools (New Relic) and also mimicing the format of the http spans. Since an http span isMETHOD route, I followed a similar format ofOP name so the spans look likeQUERY GetAllUsersById.

I don't love the prefix because I already can see where the span is coming from by the instrumentation library (see the screenshots in description), but I also don't know if this is the case on other tools like Jaeger, which I'd like to setup eventually. I'm down to change it if we find it hard to parse as we use it, does that sound ok?

mafredri reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that sounds perfectly reasonable. 👍🏻

return strings.ToUpper(op)
}

s := strings.Split(strings.TrimPrefix(q, qPrefix), " ")[0]
Copy link
Member

Choose a reason for hiding this comment

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

Just a small perf suggestion to avoid processing the entire query.

Suggested change
s:=strings.Split(strings.TrimPrefix(q,qPrefix)," ")[0]
s:=strings.SplitN(strings.TrimPrefix(q,qPrefix)," ",1)[0]

f0ssel reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

of course! I was only paying attention to the first line lol

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

This looks great! I just have one concern regarding the case where we fail to register the tracing driver.

@f0sself0ssel merged commit0effb71 intomainMay 20, 2022
@f0sself0ssel deleted the f0ssel/otel-sql branchMay 20, 2022 15:51
kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mafredrimafredrimafredri approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

@deansheatherdeansheatherdeansheather approved these changes

@coadlercoadlerAwaiting requested review from coadler

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@f0ssel@mafredri@johnstcn@deansheather

[8]ページ先頭

©2009-2025 Movatter.jp