Skip to content

Commit

Permalink
Merge branch 'main' into mtoff/refactor-report-health-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 authored Dec 23, 2024
2 parents c3e21c0 + d393324 commit c7a40e5
Show file tree
Hide file tree
Showing 40 changed files with 443 additions and 210 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
scenario: APPSEC_CORRUPTED_RULES
- weblog-variant: net-http
scenario: APPSEC_LOW_WAF_TIMEOUT
- weblog-variant: net-http
scenario: APPSEC_STANDALONE
- weblog-variant: net-http
scenario: APPSEC_CUSTOM_OBFUSCATION
# APM scenarios requiring specific environment settings
Expand Down
4 changes: 2 additions & 2 deletions contrib/99designs/gqlgen/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (t *gqlTracer) Validate(_ graphql.ExecutableSchema) error {
func (t *gqlTracer) InterceptOperation(ctx context.Context, next graphql.OperationHandler) graphql.ResponseHandler {
opCtx := graphql.GetOperationContext(ctx)
span, ctx := t.createRootSpan(ctx, opCtx)
ctx, req := graphqlsec.StartRequestOperation(ctx, graphqlsec.RequestOperationArgs{
ctx, req := graphqlsec.StartRequestOperation(ctx, span, graphqlsec.RequestOperationArgs{
RawQuery: opCtx.RawQuery,
OperationName: opCtx.OperationName,
Variables: opCtx.Variables,
Expand Down Expand Up @@ -137,7 +137,7 @@ func (t *gqlTracer) InterceptOperation(ctx context.Context, next graphql.Operati
}

query.Finish(executionOperationRes)
req.Finish(span, requestOperationRes)
req.Finish(requestOperationRes)
return response
}
}
Expand Down
8 changes: 4 additions & 4 deletions contrib/google.golang.org/grpc/appsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func appsecUnaryHandlerMiddleware(method string, span ddtrace.Span, handler grpc
remoteAddr = p.Addr.String()
}

ctx, op, blockAtomic := grpcsec.StartHandlerOperation(ctx, grpcsec.HandlerOperationArgs{
ctx, op, blockAtomic := grpcsec.StartHandlerOperation(ctx, span, grpcsec.HandlerOperationArgs{
Method: method,
Metadata: md,
RemoteAddr: remoteAddr,
Expand All @@ -55,7 +55,7 @@ func appsecUnaryHandlerMiddleware(method string, span ddtrace.Span, handler grpc
if statusErr, ok := rpcErr.(interface{ GRPCStatus() *status.Status }); ok && !applyAction(blockAtomic, &rpcErr) {
statusCode = int(statusErr.GRPCStatus().Code())
}
op.Finish(span, grpcsec.HandlerOperationRes{StatusCode: statusCode})
op.Finish(grpcsec.HandlerOperationRes{StatusCode: statusCode})
applyAction(blockAtomic, &rpcErr)
}()

Expand Down Expand Up @@ -90,7 +90,7 @@ func appsecStreamHandlerMiddleware(method string, span ddtrace.Span, handler grp
}

// Create the handler operation and listen to blocking gRPC actions to detect a blocking condition
ctx, op, blockAtomic := grpcsec.StartHandlerOperation(ctx, grpcsec.HandlerOperationArgs{
ctx, op, blockAtomic := grpcsec.StartHandlerOperation(ctx, span, grpcsec.HandlerOperationArgs{
Method: method,
Metadata: md,
RemoteAddr: remoteAddr,
Expand All @@ -104,7 +104,7 @@ func appsecStreamHandlerMiddleware(method string, span ddtrace.Span, handler grp
statusCode = int(res.Status())
}

op.Finish(span, grpcsec.HandlerOperationRes{StatusCode: statusCode})
op.Finish(grpcsec.HandlerOperationRes{StatusCode: statusCode})
applyAction(blockAtomic, &rpcErr)
}()

Expand Down
18 changes: 9 additions & 9 deletions contrib/google.golang.org/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,20 +520,20 @@ func TestStreamSendsErrorCode(t *testing.T) {
// to flush the spans
_, _ = stream.Recv()

containsErrorCode := false
spans := mt.FinishedSpans()

// check if at least one span has error code
// check if at least one span with spank.kind=server has error code
var span mocktracer.Span
for _, s := range spans {
if s.Tag(tagCode) == wantCode {
containsErrorCode = true
if s.Tag(tagCode) != wantCode {
continue
}
if s.Tag(ext.SpanKind) != ext.SpanKindServer {
continue
}
span = s
}
assert.True(t, containsErrorCode, "at least one span should contain error code, the spans were:\n%v", spans)

// ensure that last span contains error code also
gotLastSpanCode := spans[len(spans)-1].Tag(tagCode)
assert.Equal(t, wantCode, gotLastSpanCode, "last span should contain error code")
assert.NotNilf(t, span, "at least one span should contain error code, the spans were:\n%v", spans)
}

// fixtureServer a dummy implementation of our grpc fixtureServer.
Expand Down
4 changes: 2 additions & 2 deletions contrib/graph-gophers/graphql-go/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (t *Tracer) TraceQuery(ctx context.Context, queryString, operationName stri
}
span, ctx := ddtracer.StartSpanFromContext(ctx, t.cfg.querySpanName, opts...)

ctx, request := graphqlsec.StartRequestOperation(ctx, graphqlsec.RequestOperationArgs{
ctx, request := graphqlsec.StartRequestOperation(ctx, span, graphqlsec.RequestOperationArgs{
RawQuery: queryString,
OperationName: operationName,
Variables: variables,
Expand All @@ -92,7 +92,7 @@ func (t *Tracer) TraceQuery(ctx context.Context, queryString, operationName stri
err = fmt.Errorf("%s (and %d more errors)", errs[0], n-1)
}
defer span.Finish(ddtracer.WithError(err))
defer request.Finish(span, graphqlsec.RequestOperationRes{Error: err})
defer request.Finish(graphqlsec.RequestOperationRes{Error: err})
query.Finish(graphqlsec.ExecutionOperationRes{Error: err})
}
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/graphql-go/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type contextData struct {
// finish closes the top-level request operation, as well as the server span.
func (c *contextData) finish(data any, err error) {
defer c.serverSpan.Finish(tracer.WithError(err))
c.requestOp.Finish(c.serverSpan, graphqlsec.RequestOperationRes{Data: data, Error: err})
c.requestOp.Finish(graphqlsec.RequestOperationRes{Data: data, Error: err})
}

var extensionName = reflect.TypeOf((*datadogExtension)(nil)).Elem().Name()
Expand All @@ -97,7 +97,7 @@ func (i datadogExtension) Init(ctx context.Context, params *graphql.Params) cont
tracer.Tag(ext.Component, componentName),
tracer.Measured(),
)
ctx, request := graphqlsec.StartRequestOperation(ctx, graphqlsec.RequestOperationArgs{
ctx, request := graphqlsec.StartRequestOperation(ctx, span, graphqlsec.RequestOperationArgs{
RawQuery: params.RequestString,
Variables: params.VariableValues,
OperationName: params.OperationName,
Expand Down
6 changes: 3 additions & 3 deletions contrib/miekg/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func startServer(t *testing.T, traced bool) (*dns.Server, func()) {
if traced {
h = dnstrace.WrapHandler(h)
}
addr := getFreeAddr(t).String()
addr := getAddr(t).String()
server := &dns.Server{
Addr: addr,
Net: "udp",
Expand Down Expand Up @@ -190,8 +190,8 @@ func assertClientSpan(t *testing.T, s mocktracer.Span) {
assert.Equal(t, ext.SpanKindClient, s.Tag(ext.SpanKind))
}

func getFreeAddr(t *testing.T) net.Addr {
li, err := net.Listen("tcp", "127.0.0.1:0")
func getAddr(t *testing.T) net.Addr {
li, err := net.Listen("tcp4", "127.0.0.1:2020")
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion contrib/net/http/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"

"gopkg.in/DataDog/dd-trace-go.v1/appsec/events"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
Expand Down
2 changes: 2 additions & 0 deletions ddtrace/tracer/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type startupInfo struct {
FeatureFlags []string `json:"feature_flags"`
PropagationStyleInject string `json:"propagation_style_inject"` // Propagation style for inject
PropagationStyleExtract string `json:"propagation_style_extract"` // Propagation style for extract
TracingAsTransport bool `json:"tracing_as_transport"` // Whether the tracer is disabled and other products are using it as a transport
}

// checkEndpoint tries to connect to the URL specified by endpoint.
Expand Down Expand Up @@ -147,6 +148,7 @@ func logStartup(t *tracer) {
FeatureFlags: featureFlags,
PropagationStyleInject: injectorNames,
PropagationStyleExtract: extractorNames,
TracingAsTransport: t.config.tracingAsTransport,
}
if _, _, err := samplingRulesFromEnv(); err != nil {
info.SamplingRulesError = fmt.Sprintf("%s", err)
Expand Down
Loading

0 comments on commit c7a40e5

Please sign in to comment.