-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Trajan0x <[email protected]>
- Loading branch information
Showing
10 changed files
with
101 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,2 @@ | ||
// Package slackertrace provides a Slacker trace exporter for OpenTelemetry. | ||
package slackertrace |
This file contains 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 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,38 @@ | ||
package slackertrace | ||
|
||
import ( | ||
"fmt" | ||
"github.com/slack-io/slacker" | ||
"github.com/synapsecns/sanguine/core/metrics" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
// TracingMiddleware is a middleware that creates a new span for each command. | ||
func TracingMiddleware(handler metrics.Handler) slacker.CommandMiddlewareHandler { | ||
return func(next slacker.CommandHandler) slacker.CommandHandler { | ||
return func(cmdCtx *slacker.CommandContext) { | ||
ctx, span := handler.Tracer().Start(cmdCtx.Context(), fmt.Sprintf("command.%s", cmdCtx.Definition().Command), trace.WithAttributes( | ||
attribute.String("user_id", cmdCtx.Event().UserID), | ||
attribute.String("channel_id", retrieveChannelIfExists(cmdCtx.Event())), | ||
)) | ||
|
||
cmdCtx.WithContext(ctx) | ||
|
||
defer func() { | ||
metrics.EndSpan(span) | ||
}() | ||
|
||
next(cmdCtx) | ||
} | ||
} | ||
} | ||
|
||
const unknownChannel = "unknown" | ||
|
||
func retrieveChannelIfExists(event *slacker.MessageEvent) string { | ||
if event != nil && event.Channel != nil { | ||
return event.Channel.ID | ||
} | ||
return unknownChannel | ||
} |
This file contains 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