-
-
Notifications
You must be signed in to change notification settings - Fork 86
feat(ext): add observability extension hooks #666
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5aaef49
feat(ext): add observability extension hooks
SantiagoDePolonia eb796ee
fix(ext): harden telemetry extension hooks
SantiagoDePolonia cefea31
Merge remote-tracking branch 'origin/main' into feat/otel
SantiagoDePolonia bfe90af
fix(ext): align telemetry metadata resolution
SantiagoDePolonia c90d92f
fix(telemetry): preserve passthrough metadata
SantiagoDePolonia 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
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,43 @@ | ||
| package config | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestResolveMetricsEndpoint(t *testing.T) { | ||
| tests := map[string]string{ | ||
| "": "/metrics", | ||
| "metrics": "/metrics", | ||
| "/monitoring/metrics/": "/monitoring/metrics", | ||
| "/foo/../metrics-custom": "/metrics-custom", | ||
| "v1/models": "/metrics", | ||
| "../v1/models": "/metrics", | ||
| "/v1/models": "/metrics", | ||
| "/p/internal": "/metrics", | ||
| } | ||
| for input, want := range tests { | ||
| if got := ResolveMetricsEndpoint(input); got != want { | ||
| t.Errorf("ResolveMetricsEndpoint(%q) = %q, want %q", input, got, want) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestResolveMetricsEndpointWithPprof(t *testing.T) { | ||
| tests := map[string]struct { | ||
| endpoint string | ||
| pprofEnabled bool | ||
| want string | ||
| }{ | ||
| "pprof disabled": {endpoint: "/debug/pprof", want: "/debug/pprof"}, | ||
| "pprof root conflict": {endpoint: "/debug/pprof", pprofEnabled: true, want: "/metrics"}, | ||
| "pprof child conflict": { | ||
| endpoint: "/debug/pprof/goroutine", pprofEnabled: true, want: "/metrics", | ||
| }, | ||
| "custom endpoint": {endpoint: "monitoring/metrics", pprofEnabled: true, want: "/monitoring/metrics"}, | ||
| } | ||
| for name, test := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| if got := ResolveMetricsEndpointWithPprof(test.endpoint, test.pprofEnabled); got != test.want { | ||
| t.Errorf("ResolveMetricsEndpointWithPprof(%q, %v) = %q, want %q", test.endpoint, test.pprofEnabled, got, test.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
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,58 @@ | ||
| package ext | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
| ) | ||
|
|
||
| // UpstreamCall describes one logical call from GoModel to a configured model | ||
| // provider. Transport retries are folded into the same call. | ||
| type UpstreamCall struct { | ||
| // Provider is the configured provider instance name. ProviderType is its | ||
| // implementation type (for example "openai" or "anthropic"). | ||
| Provider string | ||
| ProviderType string | ||
| Model string | ||
| // Operation is the semantic GenAI operation selected by the provider | ||
| // adapter (for example "chat", "generate_content", or "embeddings"). | ||
| // It is empty for calls that are not model inference operations. | ||
| Operation string | ||
| Endpoint string | ||
| Method string | ||
| Stream bool | ||
| // StreamUncertain is true when a bounded opaque-body peek could not | ||
| // determine request intent. A later first-chunk event can still confirm SSE. | ||
| StreamUncertain bool | ||
| } | ||
|
|
||
| // UpstreamResult describes a completed logical provider call. For streaming | ||
| // calls completion means that the upstream stream was established, not that | ||
| // its response body was fully consumed. | ||
| type UpstreamResult struct { | ||
| UpstreamCall | ||
| StatusCode int | ||
| Duration time.Duration | ||
| Err error | ||
| } | ||
|
|
||
| // UpstreamObserver observes calls to model providers without participating in | ||
| // request handling. Start may return a derived context (for example one that | ||
| // carries a trace span); the same context is passed to End and to the provider | ||
| // request. Implementations must be safe for concurrent use and should not | ||
| // block the request path. | ||
| // | ||
| // Core contains observer panics so optional instrumentation cannot fail model | ||
| // traffic. Every successful Start invocation is paired with one End call. | ||
| type UpstreamObserver interface { | ||
| Name() string | ||
| Start(ctx context.Context, call UpstreamCall) context.Context | ||
| End(ctx context.Context, result UpstreamResult) | ||
| } | ||
|
|
||
| // UpstreamStreamObserver optionally observes the first response chunk of a | ||
| // successful streaming call. Duration is measured from request issuance until | ||
| // the first body read that returns bytes; calls that end without bytes are not | ||
| // reported. | ||
| type UpstreamStreamObserver interface { | ||
| FirstResponseChunk(ctx context.Context, result UpstreamResult) | ||
| } |
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.