-
Notifications
You must be signed in to change notification settings - Fork 4
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
Update go-client - new telemetry #1330
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7790cc6
Update go-client and other deps
michaljurecko 90ddcf9
Fix test after update
michaljurecko 005cd6c
Use new go-client/request package
michaljurecko 569d0b4
Register opencensus bridge for go-cloud lib telemetry
michaljurecko cbac529
Delete old oteldd/httpclient
michaljurecko 5cee2ff
Update go-client 1.16.0
michaljurecko 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 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 |
---|---|---|
|
@@ -3,37 +3,33 @@ package httpclient | |
|
||
import ( | ||
"io" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/keboola/go-client/pkg/client" | ||
ddHttp "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext" | ||
"github.com/keboola/go-client/pkg/client/trace" | ||
"github.com/keboola/go-client/pkg/client/trace/otel" | ||
"go.opentelemetry.io/contrib/propagators/b3" | ||
|
||
"github.com/keboola/keboola-as-code/internal/pkg/env" | ||
"github.com/keboola/keboola-as-code/internal/pkg/telemetry/oteldd" | ||
"github.com/keboola/keboola-as-code/internal/pkg/utils/strhelper" | ||
"github.com/keboola/keboola-as-code/internal/pkg/telemetry" | ||
) | ||
|
||
type Config struct { | ||
userAgent string | ||
envs env.Provider | ||
telemetry telemetry.Telemetry | ||
debugWriter io.Writer | ||
dumpWriter io.Writer | ||
} | ||
|
||
type Option func(c *Config) | ||
|
||
func WithEnvs(envs env.Provider) Option { | ||
func WithUserAgent(v string) Option { | ||
return func(c *Config) { | ||
c.envs = envs | ||
c.userAgent = v | ||
} | ||
} | ||
|
||
func WithUserAgent(v string) Option { | ||
func WithTelemetry(v telemetry.Telemetry) Option { | ||
return func(c *Config) { | ||
c.userAgent = v | ||
c.telemetry = v | ||
} | ||
} | ||
|
||
|
@@ -59,48 +55,34 @@ func New(opts ...Option) client.Client { | |
// Force HTTP2 transport | ||
transport := client.HTTP2Transport() | ||
|
||
// DataDog low-level tracing (raw http requests) | ||
if conf.envs != nil && oteldd.IsDataDogEnabled(conf.envs) { | ||
transport = ddHttp.WrapRoundTripper( | ||
transport, | ||
ddHttp.WithBefore(func(request *http.Request, span ddtrace.Span) { | ||
// We use "http.request" operation name for request to the API, | ||
// so requests to other API must have different operation name. | ||
span.SetOperationName("kac.api.client.http.request") | ||
span.SetTag("http.host", request.URL.Host) | ||
if dotPos := strings.IndexByte(request.URL.Host, '.'); dotPos > 0 { | ||
// E.g. connection, encryption, scheduler ... | ||
span.SetTag("http.hostPrefix", request.URL.Host[:dotPos]) | ||
} | ||
span.SetTag(ext.EventSampleRate, 1.0) | ||
span.SetTag(ext.HTTPURL, request.URL.Redacted()) | ||
span.SetTag("http.path", request.URL.Path) | ||
span.SetTag("http.query", request.URL.Query().Encode()) | ||
}), | ||
ddHttp.RTWithResourceNamer(func(r *http.Request) string { | ||
// Set resource name to request path | ||
return strhelper.MustURLPathUnescape(r.URL.RequestURI()) | ||
})) | ||
} | ||
|
||
// Create client | ||
cl := client.New(). | ||
WithTransport(transport). | ||
WithUserAgent(conf.userAgent) | ||
|
||
// Enable telemetry | ||
if conf.telemetry != nil { | ||
cl = cl.WithTelemetry( | ||
conf.telemetry.TracerProvider(), | ||
conf.telemetry.MeterProvider(), | ||
otel.WithRedactedHeaders("X-StorageAPI-Token", "X-KBC-ManageApiToken"), | ||
otel.WithPropagators( | ||
// DataDog supports multiple propagations: tracecontext, B3, legacy DataDog, ... | ||
// W3C tracecontext propagator (propagation.TraceContext{}) is not working with the Storage API dd-trace-php , | ||
// so the B3 propagator is used. | ||
b3.New(b3.WithInjectEncoding(b3.B3MultipleHeader)), | ||
), | ||
) | ||
} | ||
|
||
Comment on lines
+63
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Namiesto DD telemetrie (low/high) sa pouzije telemetria, ktora je uz v go-client. |
||
// Log each HTTP client request/response as debug message | ||
if conf.debugWriter != nil { | ||
cl = cl.AndTrace(client.LogTracer(conf.debugWriter)) | ||
cl = cl.AndTrace(trace.LogTracer(conf.debugWriter)) | ||
} | ||
|
||
// Dump each HTTP client request/response body | ||
if conf.dumpWriter != nil { | ||
cl = cl.AndTrace(client.DumpTracer(conf.dumpWriter)) | ||
} | ||
|
||
// DataDog high-level tracing (api client requests) | ||
if conf.envs != nil && oteldd.IsDataDogEnabled(conf.envs) { | ||
cl = cl.AndTrace(oteldd.DDTraceFactory()) | ||
cl = cl.AndTrace(trace.DumpTracer(conf.dumpWriter)) | ||
} | ||
|
||
return cl | ||
|
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 was deleted.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
httpclient
je pkg vkac
repe, factory prego-client
klienta.Pridavam tu podporu telemetri, ... envs sa nikde uz nepouzivali, tak som ich vyhodil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niekedy sme mali
envs
na roznych miestach v kode, ... teraz ma kazda service uz svojconfig
, ale tu som envs zabudol zmazat.