-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include additional metadata for tracing the collaboration service
- Loading branch information
1 parent
24b940d
commit 6204b07
Showing
4 changed files
with
55 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
func CollaborationTracingMiddleware(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
wopiContext, err := WopiContextFromCtx(r.Context()) | ||
if err != nil { | ||
// if we can't get the context, skip this middleware | ||
next.ServeHTTP(w, r) | ||
} | ||
|
||
span := trace.SpanFromContext(r.Context()) | ||
|
||
wopiMethod := r.Header.Get("X-WOPI-Override") | ||
|
||
wopiFile := wopiContext.FileReference | ||
wopiUser := wopiContext.User.GetId() | ||
|
||
attrs := []attribute.KeyValue{ | ||
attribute.String("ocis.wopi.method", wopiMethod), | ||
attribute.String("ocis.wopi.resource.id.storage", wopiFile.GetResourceId().GetStorageId()), | ||
attribute.String("ocis.wopi.resource.id.opaque", wopiFile.GetResourceId().GetOpaqueId()), | ||
attribute.String("ocis.wopi.resource.id.space", wopiFile.GetResourceId().GetSpaceId()), | ||
attribute.String("ocis.wopi.resource.path", wopiFile.GetPath()), | ||
attribute.String("ocis.wopi.user.idp", wopiUser.GetIdp()), | ||
attribute.String("ocis.wopi.user.opaque", wopiUser.GetOpaqueId()), | ||
attribute.String("ocis.wopi.user.type", wopiUser.GetType().String()), | ||
} | ||
span.SetAttributes(attrs...) | ||
|
||
next.ServeHTTP(w, r) | ||
}) | ||
} |
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