forked from raystack/guardian
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track external client logs (#183)
* feat: track external client logs * feat: track external client logs * fix bigquery provider test * fix: some test cases * add gitlab otel * add oauth scope for each service * add metric into external client * refactor otel http client * coverage test * coverage test * coverage test * increase metric interval to 15s * fix data race * fix go mod * resolve comments --------- Co-authored-by: Lifosmin Simon <[email protected]>
- Loading branch information
Showing
29 changed files
with
417 additions
and
72 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
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,35 @@ | ||
package otelhttpclient | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" | ||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
type labelerContextKeyType int | ||
|
||
const lablelerContextKey labelerContextKeyType = 0 | ||
|
||
// AnnotateRequest adds telemetry related annotations to request context and returns. | ||
// The request context on the returned request should be retained. | ||
// Ensure `route` is a route template and not actual URL to prevent high cardinality | ||
// on the metrics. | ||
func AnnotateRequest(req *http.Request, route string) *http.Request { | ||
ctx := req.Context() | ||
|
||
l := &otelhttp.Labeler{} | ||
l.Add(attribute.String(attributeHTTPRoute, route)) | ||
|
||
return req.WithContext(context.WithValue(ctx, lablelerContextKey, l)) | ||
} | ||
|
||
// LabelerFromContext returns the labeler annotation from the context if exists. | ||
func LabelerFromContext(ctx context.Context) (*otelhttp.Labeler, bool) { | ||
l, ok := ctx.Value(lablelerContextKey).(*otelhttp.Labeler) | ||
if !ok { | ||
l = &otelhttp.Labeler{} | ||
} | ||
return l, ok | ||
} |
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,15 @@ | ||
package otelhttpclient | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
func New(name string, client *http.Client) *http.Client { | ||
if client == nil { | ||
return &http.Client{ | ||
Transport: NewHTTPTransport(nil, name), | ||
} | ||
} | ||
client.Transport = NewHTTPTransport(client.Transport, name) | ||
return client | ||
} |
Oops, something went wrong.