- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.1k
 
feat: OpenTelemetry Tracing #13899
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
          
     Merged
      
      
            elliott-with-the-longest-name-on-github
  merged 89 commits into
  main
from
elliott/init-tracing
  
      
      
   
  Aug 14, 2025 
      
    
  
     Merged
                    feat: OpenTelemetry Tracing #13899
Changes from 76 commits
      Commits
    
    
            Show all changes
          
          
            89 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0c3aad6
              
                feat: Initial tracing setup (peer deps + utils)
              
              
                elliott-with-the-longest-name-on-github 62777fe
              
                Merge branch 'main' into elliott/init-tracing
              
              
                teemingc 78a65ea
              
                feat: Add tracing to `load`, server actions, and `handle`/`resolve` (…
              
              
                elliott-with-the-longest-name-on-github f65b78f
              
                Update packages/kit/src/exports/public.d.ts
              
              
                elliott-with-the-longest-name-on-github 77d447f
              
                chore: Switch to `tracing: { server: boolean }`
              
              
                elliott-with-the-longest-name-on-github 965bfea
              
                chore: Make enablement / importing of otel make more sense
              
              
                elliott-with-the-longest-name-on-github 65752bc
              
                chore: merge_tracing function
              
              
                elliott-with-the-longest-name-on-github e50615b
              
                fix rich's bad comment that shouldn't have ever existed >:(
              
              
                elliott-with-the-longest-name-on-github 5b583ec
              
                test stuff
              
              
                elliott-with-the-longest-name-on-github 90e961d
              
                Update packages/kit/test/utils.js
              
              
                elliott-with-the-longest-name-on-github dd516a9
              
                i am truly among the dumbest
              
              
                elliott-with-the-longest-name-on-github 0cf24bc
              
                Merge branch 'main' into elliott/init-tracing
              
              
                elliott-with-the-longest-name-on-github 962daf7
              
                types
              
              
                elliott-with-the-longest-name-on-github 6a81d8b
              
                remove now-useless comment
              
              
                elliott-with-the-longest-name-on-github f143f5b
              
                lockfile
              
              
                elliott-with-the-longest-name-on-github fc3f734
              
                fix dumb import analysis
              
              
                elliott-with-the-longest-name-on-github 4b64316
              
                changeset
              
              
                elliott-with-the-longest-name-on-github 3192797
              
                Merge branch 'main' into elliott/init-tracing
              
              
                elliott-with-the-longest-name-on-github b6b7d6a
              
                fix: conflict
              
              
                elliott-with-the-longest-name-on-github 60540ce
              
                i do not know why this fixed it but it did
              
              
                elliott-with-the-longest-name-on-github 723d5a4
              
                Merge remote-tracking branch 'origin/main' into elliott/init-tracing
              
              
                elliott-with-the-longest-name-on-github 091eaef
              
                idk man
              
              
                elliott-with-the-longest-name-on-github acf66e9
              
                i do not understand why this fixed anything
              
              
                elliott-with-the-longest-name-on-github 587be22
              
                chore: catalog node types
              
              
                elliott-with-the-longest-name-on-github 83a24aa
              
                upstream
              
              
                elliott-with-the-longest-name-on-github 874717f
              
                fix: idiocy on my part tbh
              
              
                elliott-with-the-longest-name-on-github 1d06059
              
                optionally load tracing, add remote functions
              
              
                elliott-with-the-longest-name-on-github 4c95395
              
                chore: Better attributes for actions
              
              
                elliott-with-the-longest-name-on-github 45d3eaa
              
                only load module if exists
              
              
                elliott-with-the-longest-name-on-github 7a91d03
              
                Merge remote-tracking branch 'origin/main' into elliott/init-tracing
              
              
                elliott-with-the-longest-name-on-github cbfaa03
              
                try this to prevent package issues
              
              
                elliott-with-the-longest-name-on-github 0001ab9
              
                fix: unit tests
              
              
                elliott-with-the-longest-name-on-github 4486b21
              
                fix again
              
              
                elliott-with-the-longest-name-on-github 30ffc68
              
                move event.js to internal
              
              
                elliott-with-the-longest-name-on-github b526831
              
                move event-state to internal
              
              
                elliott-with-the-longest-name-on-github 5954ae4
              
                changeset and docs
              
              
                elliott-with-the-longest-name-on-github fb508f7
              
                types
              
              
                elliott-with-the-longest-name-on-github 4ccef4b
              
                types
              
              
                elliott-with-the-longest-name-on-github 21f84be
              
                fix: use resolve module
              
              
                elliott-with-the-longest-name-on-github eb3e876
              
                feat: `tracing.server.ts` (#14117)
              
              
                elliott-with-the-longest-name-on-github b57f927
              
                Merge remote-tracking branch 'origin/main' into elliott/init-tracing
              
              
                elliott-with-the-longest-name-on-github c73569c
              
                server file option
              
              
                elliott-with-the-longest-name-on-github f654784
              
                docs
              
              
                elliott-with-the-longest-name-on-github 5f5129c
              
                feedback
              
              
                elliott-with-the-longest-name-on-github 5c3cc72
              
                fix: adapters
              
              
                elliott-with-the-longest-name-on-github afc7e15
              
                Merge remote-tracking branch 'origin/main' into elliott/init-tracing
              
              
                elliott-with-the-longest-name-on-github 8c804a6
              
                fix event state
              
              
                elliott-with-the-longest-name-on-github 00eec4a
              
                harder
              
              
                elliott-with-the-longest-name-on-github 5660820
              
                exit hell
              
              
                elliott-with-the-longest-name-on-github 3a8b5ac
              
                Update packages/kit/src/exports/vite/utils.js
              
              
                elliott-with-the-longest-name-on-github 8e0ba7a
              
                address feedback
              
              
                elliott-with-the-longest-name-on-github e65a25e
              
                Update documentation/docs/30-advanced/68-observability.md
              
              
                elliott-with-the-longest-name-on-github 06486db
              
                Update documentation/docs/30-advanced/68-observability.md
              
              
                elliott-with-the-longest-name-on-github dc35aa1
              
                Merge branch 'elliott/init-tracing' of github.com:sveltejs/kit into e…
              
              
                elliott-with-the-longest-name-on-github 512538e
              
                Update documentation/docs/30-advanced/68-observability.md
              
              
                elliott-with-the-longest-name-on-github 4b09980
              
                Update documentation/docs/30-advanced/68-observability.md
              
              
                elliott-with-the-longest-name-on-github a111b7d
              
                Update documentation/docs/30-advanced/68-observability.md
              
              
                elliott-with-the-longest-name-on-github 3188b73
              
                we can't use  here... long story but it breaks the docs
              
              
                Rich-Harris 268cd82
              
                destroy event-state
              
              
                elliott-with-the-longest-name-on-github 8126882
              
                Merge branch 'elliott/init-tracing' of github.com:sveltejs/kit into e…
              
              
                elliott-with-the-longest-name-on-github 738db55
              
                Merge remote-tracking branch 'origin/main' into elliott/init-tracing
              
              
                elliott-with-the-longest-name-on-github a1cad37
              
                Update documentation/docs/30-advanced/68-observability.md
              
              
                Rich-Harris 3322f89
              
                remove config
              
              
                elliott-with-the-longest-name-on-github 2fe0fbf
              
                last feedbacks
              
              
                elliott-with-the-longest-name-on-github 2ad5182
              
                Merge branch 'elliott/init-tracing' of github.com:sveltejs/kit into e…
              
              
                elliott-with-the-longest-name-on-github 98669e6
              
                tests
              
              
                elliott-with-the-longest-name-on-github 0c03fbe
              
                fix type generation and remove hack
              
              
                teemingc f1d9fe2
              
                Merge branch 'main' into elliott/init-tracing
              
              
                teemingc 54831e7
              
                em dashes and tabs
              
              
                Rich-Harris 71b4cdd
              
                Update packages/kit/src/exports/public.d.ts
              
              
                Rich-Harris d15b9f5
              
                bump since tags
              
              
                Rich-Harris 6edfc8a
              
                Apply suggestions from code review
              
              
                Rich-Harris b16c012
              
                Update packages/kit/src/exports/vite/dev/index.js
              
              
                Rich-Harris 04b7fde
              
                Merge branch 'main' into elliott/init-tracing
              
              
                Rich-Harris 6a73667
              
                oops
              
              
                Rich-Harris f34728a
              
                Update documentation/docs/30-advanced/68-observability.md
              
              
                Rich-Harris ace50a3
              
                fix: type nightmares
              
              
                elliott-with-the-longest-name-on-github bf8cb46
              
                Merge branch 'elliott/init-tracing' of github.com:sveltejs/kit into e…
              
              
                elliott-with-the-longest-name-on-github f0acd03
              
                bump since tags
              
              
                Rich-Harris 7334888
              
                smarter
              
              
                elliott-with-the-longest-name-on-github 7d26bf4
              
                Merge branch 'elliott/init-tracing' of github.com:sveltejs/kit into e…
              
              
                elliott-with-the-longest-name-on-github 281cdb4
              
                types
              
              
                elliott-with-the-longest-name-on-github 0a1834b
              
                hopefully I oneshot this with my brain
              
              
                elliott-with-the-longest-name-on-github bd73dc9
              
                last fixes
              
              
                elliott-with-the-longest-name-on-github 50d942a
              
                fix
              
              
                elliott-with-the-longest-name-on-github d9ab921
              
                fix
              
              
                elliott-with-the-longest-name-on-github a7b2430
              
                small docs addition
              
              
                elliott-with-the-longest-name-on-github 477e50e
              
                fix
              
              
                elliott-with-the-longest-name-on-github ab91eed
              
                fix
              
              
                elliott-with-the-longest-name-on-github File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@sveltejs/kit': minor | ||
| --- | ||
| 
     | 
||
| feat: OpenTelemetry tracing for `handle`, `sequence`, form actions, remote functions, and `load` functions running on the server | 
  
    
      This file contains hidden or 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,9 @@ | ||
| --- | ||
| '@sveltejs/adapter-cloudflare': minor | ||
| '@sveltejs/adapter-netlify': minor | ||
| '@sveltejs/adapter-vercel': minor | ||
| '@sveltejs/adapter-node': minor | ||
| '@sveltejs/kit': minor | ||
| --- | ||
| 
     | 
||
| feat: add `tracing.server.ts` for tracing instrumentation and setup | 
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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,68 @@ | ||
| --- | ||
| title: Observability | ||
| --- | ||
| 
     | 
||
| <blockquote class="since note"> | ||
| <p>Available since 2.29</p> | ||
| </blockquote> | ||
| 
     | 
||
| > [!NOTE] This feature is experimental. Expect bugs and breaking changes in minor versions (though we'll do our best to keep those to an absolute minimum). Please provide feedback! | ||
| 
     | 
||
| Sometimes, you may need to observe how your application is behaving in order to improve performance or find the root cause of a pesky bug. To help with this, SvelteKit can emit server-side [OpenTelemetry](https://opentelemetry.io) spans for the following: | ||
| 
     | 
||
| - [`handle`](hooks#Server-hooks-handle) hook (`handle` functions running in a [`sequence`](@sveltejs-kit-hooks#sequence) will show up as children of each other and the root handle hook) | ||
| - [`load`](load) functions (includes universal `load` functions when they're run on the server) | ||
| - [Form actions](form-actions) | ||
| - [Remote functions](remote-functions) | ||
| 
     | 
||
| Just telling SvelteKit to emit spans won't get you far, though — you need to actually collect them somewhere to be able to view them. SvelteKit provides `src/tracing.server.ts` as a place to write your tracing setup and instrumentation code. It's guaranteed to be run prior to your application code being imported, providing your deployment platform supports it and your adapter is aware of it. | ||
| 
     | 
||
| To enable both of these features, add the following to your `svelte.config.js`: | ||
| 
     | 
||
| ```js | ||
| /// file: svelte.config.js | ||
| export default { | ||
| kit: { | ||
| +++experimental: { | ||
| tracing: { | ||
| server: true, | ||
| serverFile: true | ||
| } | ||
| }+++ | ||
| } | ||
| }; | ||
| ``` | ||
| 
     | 
||
| > [!NOTE] Tracing — and more significantly, tracing instrumentation — can have a nontrivial overhead. Before you go all-in on tracing, consider whether or not you really need it, or if it might be more appropriate to turn it on in development and preview environments only. | ||
| 
     | 
||
| ## Development quickstart | ||
| 
     | 
||
| To view your first trace, you'll need to set up a local collector. We'll use [Jaeger](https://www.jaegertracing.io/docs/getting-started/) in this example, as they provide an easy-to-use quickstart command. Once your collector is running locally: | ||
| 
     | 
||
| - Turn on the experimental flag mentioned above in your `svelte.config.js` file | ||
| - Use your package manager to install the dependencies you'll need | ||
| ```sh | ||
| npm i @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node @opentelemetry/exporter-trace-oltp-proto import-in-the-middle | ||
| ``` | ||
| - Create `src/tracing.server.ts` with the following: | ||
| 
     | 
||
| ```ts | ||
| import { NodeSDK } from '@opentelemetry/sdk-node'; | ||
| import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; | ||
| import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'; | ||
| import { createAddHookMessageChannel } from 'import-in-the-middle'; | ||
| import { register } from 'module'; | ||
| 
     | 
||
| const { registerOptions } = createAddHookMessageChannel(); | ||
| register('import-in-the-middle/hook.mjs', import.meta.url, registerOptions); | ||
| 
     | 
||
| const sdk = new NodeSDK({ | ||
| serviceName: 'test-sveltekit-tracing', | ||
| traceExporter: new OTLPTraceExporter(), | ||
| instrumentations: [getNodeAutoInstrumentations()] | ||
| }); | ||
| 
     | 
||
| sdk.start(); | ||
| ``` | ||
| 
     | 
||
| Any server-side requests will now begin generating traces, which you can view in Jaeger's web console at [localhost:16686](http://localhost:16686). | 
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              | 
                       There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed we used the same version everywhere and that we've switched to          
      
                  elliott-with-the-longest-name-on-github marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
            
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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 @@ | ||
| // this is just here to make sure the changes resulting from it work | 
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
  
    
      This file contains hidden or 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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.