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: implement opentelemetry for distributed tracing #706

Merged
merged 15 commits into from
Oct 24, 2024

Conversation

namkyu1999
Copy link
Member

@namkyu1999 namkyu1999 commented Jun 29, 2024

What this PR does / why we need it:

This pr implements opentelemetry codes according to this proposal.

Parent context and OTEL endpoint are passed through env(TRACE_PARENT, OTEL_EXPORTER_OTLP_ENDPOINT)

Result is like below

Screenshot 2024-07-05 at 2 20 11 PM

relevant PRs

Checklist:

  • Fixes #
  • PR messages has document related information
  • Labelled this PR & related issue with breaking-changes tag
  • PR messages has breaking changes related information
  • Labelled this PR & related issue with requires-upgrade tag
  • PR messages has upgrade related information
  • Commit has unit tests
  • Commit has integration tests
  • E2E run Required for the changes

@xavierW
Copy link

xavierW commented Jun 29, 2024 via email

namkyu1999 added 2 commits August 29, 2024 13:50
Signed-off-by: namkyu1999 <[email protected]>
Copy link
Contributor

@smitthakkar96 smitthakkar96 left a comment

Choose a reason for hiding this comment

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

This is a great start however I don't see any place where we are marking span as error in case of failure, do we plan to do this in future iterations?

Based on the experiment context it might be good to explore what span attributes might be relevant.

Lastly to be able to correlate logs with traces can we add traceID to logs?

bin/experiment/experiment.go Outdated Show resolved Hide resolved
@namkyu1999
Copy link
Member Author

namkyu1999 commented Aug 29, 2024

@smitthakkar96

This is a great start however I don't see any place where we are marking span as error in case of failure, do we plan to do this in future iterations?

I will record errors like below

if err != nil {
	span.SetStatus(codes.Error, "operationThatCouldFail failed")
	span.RecordError(err)
}

But we have over 50 chaos faults, so it can be merged in the next PR (it is a time-consuming job)

Based on the experiment context it might be good to explore what span attributes might be relevant.

Does this mean adding a span attribute to help with future queries by attribute?

Lastly to be able to correlate logs with traces can we add traceID to logs?

sure, I will add it

Signed-off-by: namkyu1999 <[email protected]>
@smitthakkar96
Copy link
Contributor

smitthakkar96 commented Aug 29, 2024

Does this mean adding a span attribute to help with future queries by attribute?

Span Attributes can be useful for queries but also they can serve as additional context when reviewing the spans. Let's take an example, you get an http request, you might wanna log the relevant headers, the request body and the path similarly in context of the experiments it might be helpful to log the parameters for the experiment, maybe the targets and any other data you think that might be helpful when looking at an error trace :)

The demo application might be a good inspiration, another source of inspiration is semantic attributes.

Lastly for future I would suggest we increase the coverage of instrumentation (can be a good task for LFX contributors) by creating spans for calls to external services such as AWS, GCP, K8s or any HTTP or DB calls this contrib package has some out of the box shims that can make it easy

But we have over 50 chaos faults, so it can be merged in the next PR (it is a time-consuming job)

Totally understandable, instrumentation quality and coverage can always be improved overtime. Your initiative paves the foundation we can build on top of, my comment was just suggestions/ideas if you have sometime maybe raise log them as Github issues so other contributors can pick them up

@namkyu1999
Copy link
Member Author

Thanks for your detailed comments @smitthakkar96 :) I am going to pave the foundation for collaborating with other contributors. Adopting a contrib package is also good idea

@namkyu1999
Copy link
Member Author

I updated contribute/developer-guide folder for using context.Context

context.Context makes context propagation automatically so i fixed all of the functions to add context.Context as a parameter.

Here is a screen shot of distributed tracing. It's a result of pod-delete chaos fault.

Screenshot 2024-09-16 at 4 53 34 PM


clients := clients.ClientSets{}
ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperiment")
Copy link
Member

Choose a reason for hiding this comment

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

As we are creating one more ctx context, it will shadow the above context var created with the same name.
Which can cause the defer function not to work. Can we use a different var name here to avoid var shadow?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -24,7 +27,9 @@ var (
)

// PrepareAWSSSMChaosByID contains the prepration and injection steps for the experiment
func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
func PrepareAWSSSMChaosByID(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSChaosByIDChaos")
Copy link
Member

Choose a reason for hiding this comment

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

We init otel SDK if otelExporterEndpoint != "". Here we are calling Tracer function without checking if the endpoint is set or not. Will it handle negative cases implicitly or should we call this conditionally?

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically, They do nothing when Otel SDK is not init.

here's a otel docs

and here's a reference PR

namkyu1999 added 4 commits October 9, 2024 20:40
Signed-off-by: namkyu1999 <[email protected]>
Signed-off-by: namkyu1999 <[email protected]>
Signed-off-by: namkyu1999 <[email protected]>
@namkyu1999
Copy link
Member Author

namkyu1999 commented Oct 9, 2024

enhance coverage

AS-IS
span: InjectXXXChaos

TO-BE
parent span: PrepareXXXFault
child span: InjectXXXFaultIn(Serial/Parallel)Mode

Screenshot 2024-10-09 at 6 59 04 PM
Screenshot 2024-10-09 at 6 58 47 PM

@ksatchit ksatchit merged commit 3ef23b0 into litmuschaos:master Oct 24, 2024
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

5 participants