Skip to content

Add tracetest example for testing instrumentation #7074

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

adity1raut
Copy link

@adity1raut adity1raut commented Jul 22, 2025

Fixes #7051

This PR adds a basic example demonstrating how to test tracing instrumentation using the tracetest.SpanRecorder from the OpenTelemetry SDK.

✅ It ensures:

  • A span is emitted when a function is instrumented
  • The span name is as expected

Inspired by:

Signed-off-by: adity1raut <[email protected]>
@adity1raut
Copy link
Author

@pellared ,
Sir, I am a first-time open source contributor, and this is my first issue. I am trying to fix it, and I sincerely request your guidance. I will follow all the guidelines properly. I understand I am taking more time than expected, but I genuinely want to solve this issue. Kindly guide me, sir

Copy link

codecov bot commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.9%. Comparing base (186def7) to head (f4b480d).
Report is 15 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7074   +/-   ##
=====================================
  Coverage   82.9%   82.9%           
=====================================
  Files        262     262           
  Lines      24460   24460           
=====================================
  Hits       20281   20281           
  Misses      3801    3801           
  Partials     378     378           

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adity1raut adity1raut marked this pull request as ready for review July 22, 2025 19:31
@adity1raut
Copy link
Author

@pellared
Sir, I have updated the PR. Please check it and share your feedback. Thank you!

@pellared pellared added Skip Changelog PRs that do not require a CHANGELOG.md entry and removed Skip Changelog PRs that do not require a CHANGELOG.md entry labels Jul 22, 2025
@pellared
Copy link
Member

pellared commented Jul 23, 2025

In my opinion the following is still not resolved:

#7052 (comment) remains unresolved, and a similar concern was raised before as well: #7052 (review)

Can you please refactor the example so that it is more similar to https://github.com/open-telemetry/opentelemetry-go/blob/main/log/logtest/example_test.go? This means e.g.:

  1. only provide one example
  2. add t := &testing.T{} // Provided by testing framework. so that we showcase that it is supposed to be used in unit tests
  3. write the test so that it passes (empty output)

@adity1raut
Copy link
Author

adity1raut commented Jul 23, 2025

Thank you for the feedback @pellared ,

I understand now that the example should closely follow the structure of log/logtest/example_test.go. I will refactor the code to include:

1,A single test example
2.t := &testing.T{} to simulate the testing environment
3.Ensure the test passes with no output

I’ll make these changes shortly. Please let me know if there’s anything else I should consider.

@dmathieu
Copy link
Member

I would recommend not using AI to generate the code and your responses on this PR. You'll learn a lot more in the process.

@adity1raut
Copy link
Author

I would recommend not using AI to generate the code and your responses on this PR. You'll learn a lot more in the process.

Thank you for the suggestion. I understand Your point and will make sure to work through the code and Responses on my own to learn Better from the process. However, I did use AI for some minor corrections while solving the issue. I appreciate your guidance

Signed-off-by: adity1raut <[email protected]>
@adity1raut
Copy link
Author

Sir, I am getting this error, but when I check it on my local system, it doesn't show any error, Could you please guide me on how to solve this issue?

@adity1raut
Copy link
Author

Screenshot 2025-07-23 163032

Signed-off-by: adity1raut <[email protected]>
@dmathieu dmathieu added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Jul 23, 2025
@dmathieu
Copy link
Member

This is still not a runnable example (you also removed some of the recommended changes from earlier, such as the global tracer provider).

I would recommend looking into https://go.dev/blog/examples to better understand what runnable examples are in Go.

@adity1raut
Copy link
Author

This is still not a runnable example (you also removed some of the recommended changes from earlier, such as the global tracer provider).

I would recommend looking into https://go.dev/blog/examples to better understand what runnable examples are in Go.

Thank you for your valuable feedback sir I will learn and update a code

@adity1raut
Copy link
Author

Screenshot 2025-07-23 220911 This is output You Want ?

Signed-off-by: adity1raut <[email protected]>
@adity1raut
Copy link
Author

adity1raut commented Jul 25, 2025

@pellared The PR is ready for review. Please have a look when you get time.

@adity1raut adity1raut requested a review from flc1125 as a code owner July 25, 2025 11:27
@adity1raut adity1raut requested a review from dmathieu July 25, 2025 11:33
@adity1raut
Copy link
Author

Screenshot 2025-07-25 174626

Hi @dmathieu , this is the output you were looking for. Can I go ahead and push the code?

@adity1raut adity1raut force-pushed the main branch 2 times, most recently from 0c95830 to cd09e80 Compare July 25, 2025 12:23
@dmathieu
Copy link
Member

This input only says the tests pass. So sure, push away.

@adity1raut
Copy link
Author

adity1raut commented Jul 25, 2025

This input only says the tests pass. So sure, push away.

I pushed the code

@adity1raut
Copy link
Author

defer func() {
_ = tp.Shutdown(ctx)
}()
This Function Can Slove this Git Action

@dmathieu
Copy link
Member

Yes, ignoring the error with an anonymous function should fix the linter.

@adity1raut adity1raut requested a review from dmathieu July 25, 2025 13:25
@adity1raut
Copy link
Author

Yes, ignoring the error with an anonymous function should fix the linter.

Printing error is Better or not

@adity1raut
Copy link
Author

adity1raut commented Jul 25, 2025

@dmathieu , please clarify, then I will make the necessary changes in the code

@dmathieu
Copy link
Member

No, printing the error makes no sense in the context of this example.

@adity1raut
Copy link
Author

No, printing the error makes no sense in the context of this example.

I will change the code. Please check the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tracetest: Add package example
3 participants