Skip to content
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

feat: send triggering transaction span to application exporter #947

Merged
merged 19 commits into from
Jul 29, 2022

Conversation

mathnogueira
Copy link
Contributor

This PR makes tracetest send the triggering transaction to the application tracing storage.

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

pe.repeatedTraceSizeCache[trace.ID.String()] = 0
}

if pe.repeatedTraceSizeCache[trace.ID.String()] >= 3 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way, we only return true if the number of spans doesn't change after 3 pollings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to remove it from this PR. This solution is too raw to be merged, I'll work on a better approach later.

@mathnogueira mathnogueira force-pushed the feat/send-span branch 2 times, most recently from 6a4104b to 7b3c12b Compare July 22, 2022 13:35
@mathnogueira mathnogueira marked this pull request as ready for review July 22, 2022 14:10
@@ -73,7 +73,9 @@ func NewPollerExecutor(

func (pe DefaultPollerExecutor) ExecuteRequest(request *PollingRequest) (bool, model.Run, error) {
run := request.run
otelTrace, err := pe.traceDB.GetTraceByID(request.ctx, run.TraceID.String())
traceId := run.TraceID.String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: go conventions suggest this should be named traceID

@@ -49,15 +57,22 @@ func (te *grpcTriggerer) Trigger(_ context.Context, test model.Test, tid trace.T
if trigger.GRPC == nil {
return response, fmt.Errorf("no settings provided for GRPC triggerer")
}

ctx, span := te.tracer.Start(context.Background(), "Tracetest Trigger")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to have the span and ctx set outside the trigger, so each trigger doesn't have to copy/paste this code

otelhttp.WithPropagators(propagators()),
),
}

ctx, span := te.tracer.Start(ctx, "Tracetest Trigger")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Type: r.TriggerResult.Type,
HTTP: r.TriggerResult.HTTP,
GRPC: r.TriggerResult.GRPC,
SpanID: r.TriggerResult.SpanID.String(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to move the spanID/TraceID from the Run to the trigger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We either do this or we pass the pointer to the run so we can set the spanID and traceID to the run instance.

@@ -11,7 +11,7 @@ import (
)

type Triggerer interface {
Trigger(context.Context, model.Test, trace.TraceID, trace.SpanID) (Response, error)
Trigger(context.Context, context.Context, model.Test, trace.TraceID, trace.SpanID) (Response, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really confusing to have 2 contexts here, so it would be great to name these params so we can know what is which


func (te *httpTriggerer) Trigger(_ context.Context, ctx context.Context, test model.Test, tid trace.TraceID, sid trace.SpanID) (Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like the first context should be called ctx and the 2nd triggerSpanCtx or something like that


func (te *grpcTriggerer) Trigger(_ context.Context, ctx context.Context, test model.Test, tid trace.TraceID, sid trace.SpanID) (Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like the first context should be called ctx and the 2nd triggerSpanCtx or something like that

@@ -93,6 +88,8 @@ func (te *grpcTriggerer) Trigger(_ context.Context, test model.Test, tid trace.T
marshaller: marshaler,
}

propagators().Inject(ctx, NewGRPCHeaderCarrier(&tReq.Metadata))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need a custom carrier? it's probablly easier to do something like:

// see https://pkg.go.dev/go.opentelemetry.io/otel/propagation#MapCarrier

propagators().Inject(ctx, propagators.MapCarrier(tReq.Metadata.Map()))
// where tReq.Metadata.Map() is a func that returns a map of key->values from the metadata

"go.opentelemetry.io/otel/propagation"
)

type GRPCHeaderCarrier struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -124,13 +127,19 @@ func (r persistentRunner) processExecQueue(job execReq) {
panic(err)
}

response, err := triggerer.Trigger(job.ctx, job.test, job.run.TraceID, job.run.SpanID)
triggerSpanCtx, span := r.triggerSpanTracer.Start(context.Background(), "Tracetest trigger")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move this to the instrumentedTriggerer.Trigger func, you wouldn't need to use 2 contexts in the Trigger interface. Given that no trigger type is actually using both contexts, I understand that this is passed just because theinstrumentedTriggerer doesn't have the triggerSpanTracer dependency. I'd rather add a dependency to the instrumentedTriggerer than to have 2 contexts on an interface that aren't actually required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only that, to do that we either have to:

  • Add a pointer to the test run to the Trigger interface
  • Change the trigger response object to have both traceID and spanID

Without either of those, we can't update the run object with the correct traceID and spanID.

@mathnogueira mathnogueira merged commit b7d0deb into main Jul 29, 2022
@mathnogueira mathnogueira deleted the feat/send-span branch July 29, 2022 20:24
cescoferraro pushed a commit that referenced this pull request Aug 2, 2022
* send triggering transaction span to application exporter

* fix test

* fix deploy

* change how we generate the triggering transaction span

* make sure all tracing tests include an assertion to check for the triggering span

* change how to get a tracer

* remove assertion for trigger span

* fix http trigger span name

* send span and change poller condition

* fix test

* revert parallel change in test

* set spanid and traceid in grpc trigger

* remove change in the poller process

* make the triggering transaction send the span

* fix tests

* inject context into grpc call

* pr changes

* refactor

* remove grpc carrier

Co-authored-by: Sebastian Choren <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants