-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Initial OSS logging adapter for http #2008
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
Open
mattdholloway
wants to merge
14
commits into
main
Choose a base branch
from
add-logging-stack-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a8bf0b0
initial logging stack for http
mattdholloway 4a2f8ed
Merge branch 'main' of https://github.com/github/github-mcp-server in…
mattdholloway ba9d315
Merge branch 'main' of https://github.com/github/github-mcp-server in…
mattdholloway cbf99e7
add metrics adapter
mattdholloway cc5b8e7
Merge branch 'main' into add-logging-stack-v2
mattdholloway 77f6e57
fix linter issues
mattdholloway 3bbfaa0
make log fields generic
mattdholloway dd57d84
Merge branch 'main' into add-logging-stack-v2
mattdholloway 2a20a2a
Update pkg/github/server_test.go
mattdholloway 1648775
Merge branch 'main' into add-logging-stack-v2
mattdholloway 7c5ea0a
Remove unused SlogMetrics adapter
mattdholloway 121daa3
Update pkg/github/dependencies.go
mattdholloway 39445b0
fmt
mattdholloway f7d3a75
Merge branch 'main' into add-logging-stack-v2
mattdholloway 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 |
|---|---|---|
|
|
@@ -4,13 +4,17 @@ import ( | |
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "log/slog" | ||
| "net/http" | ||
| "os" | ||
|
|
||
| ghcontext "github.com/github/github-mcp-server/pkg/context" | ||
| "github.com/github/github-mcp-server/pkg/http/transport" | ||
| "github.com/github/github-mcp-server/pkg/inventory" | ||
| "github.com/github/github-mcp-server/pkg/lockdown" | ||
| "github.com/github/github-mcp-server/pkg/observability" | ||
| obsvLog "github.com/github/github-mcp-server/pkg/observability/log" | ||
| obsvMetrics "github.com/github/github-mcp-server/pkg/observability/metrics" | ||
| "github.com/github/github-mcp-server/pkg/raw" | ||
| "github.com/github/github-mcp-server/pkg/scopes" | ||
| "github.com/github/github-mcp-server/pkg/translations" | ||
|
|
@@ -94,6 +98,12 @@ type ToolDependencies interface { | |
|
|
||
| // IsFeatureEnabled checks if a feature flag is enabled. | ||
| IsFeatureEnabled(ctx context.Context, flagName string) bool | ||
|
|
||
| // Logger returns the logger | ||
| Logger(ctx context.Context) obsvLog.Logger | ||
|
|
||
| // Metrics returns the metrics client | ||
| Metrics(ctx context.Context) obsvMetrics.Metrics | ||
| } | ||
|
|
||
| // BaseDeps is the standard implementation of ToolDependencies for the local server. | ||
|
|
@@ -113,6 +123,9 @@ type BaseDeps struct { | |
|
|
||
| // Feature flag checker for runtime checks | ||
| featureChecker inventory.FeatureFlagChecker | ||
|
|
||
| // Observability exporters (includes logger) | ||
| Obsv observability.Exporters | ||
| } | ||
|
|
||
| // Compile-time assertion to verify that BaseDeps implements the ToolDependencies interface. | ||
|
|
@@ -128,7 +141,14 @@ func NewBaseDeps( | |
| flags FeatureFlags, | ||
| contentWindowSize int, | ||
| featureChecker inventory.FeatureFlagChecker, | ||
| logger *slog.Logger, | ||
| ) *BaseDeps { | ||
| var obsv observability.Exporters | ||
| if logger != nil { | ||
| obsv = observability.NewExporters(obsvLog.NewSlogLogger(logger, obsvLog.InfoLevel), obsvMetrics.NewNoopMetrics()) | ||
| } else { | ||
| obsv = observability.NewExporters(obsvLog.NewNoopLogger(), obsvMetrics.NewNoopMetrics()) | ||
|
Comment on lines
+146
to
+150
|
||
| } | ||
| return &BaseDeps{ | ||
| Client: client, | ||
| GQLClient: gqlClient, | ||
|
|
@@ -138,6 +158,7 @@ func NewBaseDeps( | |
| Flags: flags, | ||
| ContentWindowSize: contentWindowSize, | ||
| featureChecker: featureChecker, | ||
| Obsv: obsv, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -170,6 +191,22 @@ func (d BaseDeps) GetFlags(_ context.Context) FeatureFlags { return d.Flags } | |
| // GetContentWindowSize implements ToolDependencies. | ||
| func (d BaseDeps) GetContentWindowSize() int { return d.ContentWindowSize } | ||
|
|
||
| // Logger implements ToolDependencies. | ||
| func (d BaseDeps) Logger(ctx context.Context) obsvLog.Logger { | ||
| if d.Obsv == nil { | ||
| return nil | ||
| } | ||
| return d.Obsv.Logger(ctx) | ||
| } | ||
|
|
||
| // Metrics implements ToolDependencies. | ||
| func (d BaseDeps) Metrics(ctx context.Context) obsvMetrics.Metrics { | ||
mattdholloway marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if d.Obsv == nil { | ||
| return nil | ||
| } | ||
| return d.Obsv.Metrics(ctx) | ||
| } | ||
|
|
||
| // IsFeatureEnabled checks if a feature flag is enabled. | ||
| // Returns false if the feature checker is nil, flag name is empty, or an error occurs. | ||
| // This allows tools to conditionally change behavior based on feature flags. | ||
|
|
@@ -247,6 +284,9 @@ type RequestDeps struct { | |
|
|
||
| // Feature flag checker for runtime checks | ||
| featureChecker inventory.FeatureFlagChecker | ||
|
|
||
| // Observability exporters (includes logger) | ||
| obsv observability.Exporters | ||
| } | ||
|
|
||
| // NewRequestDeps creates a RequestDeps with the provided clients and configuration. | ||
|
|
@@ -258,7 +298,14 @@ func NewRequestDeps( | |
| t translations.TranslationHelperFunc, | ||
| contentWindowSize int, | ||
| featureChecker inventory.FeatureFlagChecker, | ||
| logger *slog.Logger, | ||
| ) *RequestDeps { | ||
| var obsv observability.Exporters | ||
| if logger != nil { | ||
| obsv = observability.NewExporters(obsvLog.NewSlogLogger(logger, obsvLog.InfoLevel), obsvMetrics.NewNoopMetrics()) | ||
| } else { | ||
| obsv = observability.NewExporters(obsvLog.NewNoopLogger(), obsvMetrics.NewNoopMetrics()) | ||
| } | ||
| return &RequestDeps{ | ||
| apiHosts: apiHosts, | ||
| version: version, | ||
|
|
@@ -267,6 +314,7 @@ func NewRequestDeps( | |
| T: t, | ||
| ContentWindowSize: contentWindowSize, | ||
| featureChecker: featureChecker, | ||
| obsv: obsv, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -374,6 +422,16 @@ func (d *RequestDeps) GetFlags(ctx context.Context) FeatureFlags { | |
| // GetContentWindowSize implements ToolDependencies. | ||
| func (d *RequestDeps) GetContentWindowSize() int { return d.ContentWindowSize } | ||
|
|
||
| // Logger implements ToolDependencies. | ||
| func (d *RequestDeps) Logger(ctx context.Context) obsvLog.Logger { | ||
| return d.obsv.Logger(ctx) | ||
| } | ||
|
|
||
| // Metrics implements ToolDependencies. | ||
| func (d *RequestDeps) Metrics(ctx context.Context) obsvMetrics.Metrics { | ||
| return d.obsv.Metrics(ctx) | ||
| } | ||
|
|
||
| // IsFeatureEnabled checks if a feature flag is enabled. | ||
| func (d *RequestDeps) IsFeatureEnabled(ctx context.Context, flagName string) bool { | ||
| if d.featureChecker == nil || flagName == "" { | ||
|
|
||
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,29 @@ | ||
| package log | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "time" | ||
| ) | ||
|
|
||
| // Field is a key-value pair for structured logging. | ||
| // This type is backend-agnostic — adapters convert it to their native field type. | ||
| type Field struct { | ||
| Key string | ||
| Value any | ||
| } | ||
|
|
||
| // Convenience constructors for common field types. | ||
|
|
||
| func String(key, value string) Field { return Field{Key: key, Value: value} } | ||
| func Int(key string, value int) Field { return Field{Key: key, Value: value} } | ||
| func Int64(key string, value int64) Field { return Field{Key: key, Value: value} } | ||
| func Float64(key string, value float64) Field { return Field{Key: key, Value: value} } | ||
| func Bool(key string, value bool) Field { return Field{Key: key, Value: value} } | ||
| func Err(err error) Field { return Field{Key: "error", Value: err} } | ||
| func Duration(key string, value time.Duration) Field { return Field{Key: key, Value: value} } | ||
| func Any(key string, value any) Field { return Field{Key: key, Value: value} } | ||
|
|
||
| // Stringer returns the string representation of a Field. | ||
| func (f Field) String() string { | ||
| return fmt.Sprintf("%s=%v", f.Key, f.Value) | ||
| } |
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,23 @@ | ||
| package log | ||
|
|
||
| type Level struct { | ||
| level string | ||
| } | ||
|
|
||
| var ( | ||
| // DebugLevel causes all logs to be logged | ||
| DebugLevel = Level{"debug"} | ||
| // InfoLevel causes all logs of level info or more severe to be logged | ||
| InfoLevel = Level{"info"} | ||
| // WarnLevel causes all logs of level warn or more severe to be logged | ||
| WarnLevel = Level{"warn"} | ||
| // ErrorLevel causes all logs of level error or more severe to be logged | ||
| ErrorLevel = Level{"error"} | ||
| // FatalLevel causes only logs of level fatal to be logged | ||
| FatalLevel = Level{"fatal"} | ||
| ) | ||
|
|
||
| // String returns the string representation for Level | ||
| func (l Level) String() string { | ||
| return l.level | ||
| } |
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,20 @@ | ||
| package log | ||
|
|
||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| type Logger interface { | ||
| Log(ctx context.Context, level Level, msg string, fields ...Field) | ||
| Debug(msg string, fields ...Field) | ||
| Info(msg string, fields ...Field) | ||
| Warn(msg string, fields ...Field) | ||
| Error(msg string, fields ...Field) | ||
| Fatal(msg string, fields ...Field) | ||
| WithFields(fields ...Field) Logger | ||
| WithError(err error) Logger | ||
| Named(name string) Logger | ||
| WithLevel(level Level) Logger | ||
| Sync() error | ||
| Level() Level | ||
| } |
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,61 @@ | ||
| package log | ||
|
|
||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| type NoopLogger struct{} | ||
|
|
||
| var _ Logger = (*NoopLogger)(nil) | ||
|
|
||
| func NewNoopLogger() *NoopLogger { | ||
| return &NoopLogger{} | ||
| } | ||
|
|
||
| func (l *NoopLogger) Level() Level { | ||
| return DebugLevel | ||
| } | ||
|
|
||
| func (l *NoopLogger) Log(_ context.Context, _ Level, _ string, _ ...Field) { | ||
| // No-op | ||
| } | ||
|
|
||
| func (l *NoopLogger) Debug(_ string, _ ...Field) { | ||
| // No-op | ||
| } | ||
|
|
||
| func (l *NoopLogger) Info(_ string, _ ...Field) { | ||
| // No-op | ||
| } | ||
|
|
||
| func (l *NoopLogger) Warn(_ string, _ ...Field) { | ||
| // No-op | ||
| } | ||
|
|
||
| func (l *NoopLogger) Error(_ string, _ ...Field) { | ||
| // No-op | ||
| } | ||
|
|
||
| func (l *NoopLogger) Fatal(_ string, _ ...Field) { | ||
| // No-op | ||
| } | ||
|
|
||
| func (l *NoopLogger) WithFields(_ ...Field) Logger { | ||
| return l | ||
| } | ||
|
|
||
| func (l *NoopLogger) WithError(_ error) Logger { | ||
| return l | ||
| } | ||
|
|
||
| func (l *NoopLogger) Named(_ string) Logger { | ||
| return l | ||
| } | ||
|
|
||
| func (l *NoopLogger) WithLevel(_ Level) Logger { | ||
| return l | ||
| } | ||
|
|
||
| func (l *NoopLogger) Sync() error { | ||
| return nil | ||
| } |
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.