Skip to content

fix: enhance SQL query name extraction in otel tracer and fallback#3277

Merged
grutt merged 9 commits intomainfrom
fix--otel-enable-span-name-and-fallback
Mar 17, 2026
Merged

fix: enhance SQL query name extraction in otel tracer and fallback#3277
grutt merged 9 commits intomainfrom
fix--otel-enable-span-name-and-fallback

Conversation

@grutt
Copy link
Contributor

@grutt grutt commented Mar 14, 2026

Description

Enables the sql name trunc by default and falls back to meaningful text when no name is present.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Copilot AI review requested due to automatic review settings March 14, 2026 11:33
@vercel
Copy link

vercel bot commented Mar 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment Mar 17, 2026 2:15pm

Request Review

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the OpenTelemetry span naming for pgx database queries by enabling SQL statement trimming in span names (WithTrimSQLInSpanName) and replacing the previous "UNKNOWN" fallback with a more descriptive one that uses the first 6 words of the SQL statement (uppercased).

Changes:

  • Adds otelpgx.WithTrimSQLInSpanName() to the OTel pgx tracer configuration.
  • Replaces the "UNKNOWN" fallback in sqlcSpanName with a call to firstNWords(stmt, 6) for ad-hoc queries.
  • Introduces a new firstNWords helper that extracts and uppercases the first N words from a string.

You can also share your feedback on Copilot code review. Take the survey.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2026

Benchmark results

goos: linux
goarch: amd64
pkg: github.com/hatchet-dev/hatchet/internal/msgqueue/rabbitmq
cpu: AMD Ryzen 9 7950X3D 16-Core Processor          
                              │ /tmp/old.txt │            /tmp/new.txt             │
                              │    sec/op    │    sec/op     vs base               │
CompressPayloads_1x10KiB-8      100.5µ ± 12%   101.2µ ± 10%        ~ (p=0.589 n=6)
CompressPayloads_10x10KiB-8     1.107m ±  5%   1.226m ± 10%  +10.73% (p=0.002 n=6)
CompressPayloads_10x100KiB-8    11.52m ±  6%   13.33m ±  6%  +15.78% (p=0.002 n=6)
CompressPayloads_Concurrent-8   67.52µ ±  7%   87.83µ ± 15%  +30.08% (p=0.002 n=6)
geomean                         542.4µ         617.5µ        +13.83%

                              │ /tmp/old.txt │            /tmp/new.txt            │
                              │     B/op     │     B/op      vs base              │
CompressPayloads_1x10KiB-8      11.14Ki ± 2%   11.01Ki ± 2%       ~ (p=0.558 n=6)
CompressPayloads_10x10KiB-8     109.0Ki ± 1%   108.9Ki ± 1%       ~ (p=0.370 n=6)
CompressPayloads_10x100KiB-8    2.920Mi ± 1%   2.925Mi ± 1%       ~ (p=0.240 n=6)
CompressPayloads_Concurrent-8   54.28Ki ± 0%   54.19Ki ± 1%       ~ (p=0.310 n=6)
geomean                         118.5Ki        118.1Ki       -0.34%

                              │ /tmp/old.txt │            /tmp/new.txt            │
                              │  allocs/op   │ allocs/op   vs base                │
CompressPayloads_1x10KiB-8        5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=6) ¹
CompressPayloads_10x10KiB-8       32.00 ± 0%   32.00 ± 0%       ~ (p=1.000 n=6) ¹
CompressPayloads_10x100KiB-8      63.00 ± 2%   63.00 ± 2%       ~ (p=1.000 n=6)
CompressPayloads_Concurrent-8     17.00 ± 0%   17.00 ± 0%       ~ (p=1.000 n=6) ¹
geomean                           20.35        20.35       +0.00%
¹ all samples are equal

pkg: github.com/hatchet-dev/hatchet/pkg/scheduling/v1
              │ /tmp/old.txt │            /tmp/new.txt            │
              │    sec/op    │   sec/op     vs base               │
RateLimiter-8   56.67µ ± 13%   67.01µ ± 6%  +18.24% (p=0.009 n=6)

              │ /tmp/old.txt │         /tmp/new.txt          │
              │     B/op     │     B/op      vs base         │
RateLimiter-8   137.7Ki ± 0%   137.7Ki ± 0%  ~ (p=0.418 n=6)

              │ /tmp/old.txt │          /tmp/new.txt          │
              │  allocs/op   │  allocs/op   vs base           │
RateLimiter-8    1.022k ± 0%   1.022k ± 0%  ~ (p=1.000 n=6) ¹
¹ all samples are equal

Compared against main (a899c32)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@grutt grutt merged commit a3275ac into main Mar 17, 2026
50 of 51 checks passed
@grutt grutt deleted the fix--otel-enable-span-name-and-fallback branch March 17, 2026 14:31
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.

3 participants