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

Operation name/ Operation id missing for manual created threads #3569

Closed
Charlie441324219 opened this issue Mar 4, 2024 · 7 comments
Closed

Comments

@Charlie441324219
Copy link

Expected behavior

Parent thread pass Operation name/ Operation id to children thread

Actual behavior

Operation name/ Operation id is missing for manual created threads (new Thread().start()), but works fine with CompletableFuture.runAsync()

To Reproduce

		telemetry.trackEvent(baseHeaders, null, membershipNbr, "AI_LOG_PARENT_THREAD");

		new Thread(() -> telemetry.trackEvent(baseHeaders, null, membershipNbr, "AI_LOG_CHILDREN_THREAD_THREAD")).start();//Operation name/ Operation id missing HERE

		CompletableFuture.runAsync(() -> telemetry.trackEvent(baseHeaders, null, membershipNbr, "AI_LOG_CHILDREN_THREAD_THREAD_POOL"));

System information

Please provide the following information:

  • SDK Version:3.4.17
  • OS type and version:ios, java 11
  • Application Server type and version (if applicable):
  • Using spring-boot?no
  • Additional relevant libraries (with version, if applicable):

Screenshots

Screenshot 2024-03-04 at 10 34 02 AM

@jeanbisutti
Copy link
Member

@Charlie441324219 CompletableFuture is auto-instrumented but Thread is not.

You can do the following thing to propagate the context:

            io.opentelemetry.context.Context context = io.opentelemetry.context.Context.current();
			Thread thread = new Thread(new Runnable() {
			    @Override
			    public void run() {
					try (Scope scope = context.makeCurrent()) {
				telemetry.trackEvent(baseHeaders, null, membershipNbr, "AI_LOG_CHILDREN_THREAD_THREAD")).start();
					}
			    }
			});
			thread.start();

@Charlie441324219
Copy link
Author

Hi @jeanbisutti ,

Thank you so much for your help, can you please provide more details about what condition context can auto propagate or what condition it cannot ?

@jeanbisutti
Copy link
Member

de more details about what condition context can auto propagate or what condition it cannot ?

@Charlie441324219, The propagation context is automatically propagated between all the automatic instrumentations. So, the context is propagated to CompletableFuture and the HTTP request can be known.

Thread is not automatically instrumented. So, the context is not automatically propagated into the methods of Thread , and it is needed to programmatically propagate the context.

@Charlie441324219
Copy link
Author

Charlie441324219 commented Mar 5, 2024

Hi @jeanbisutti , thank you for your reply, can you please provide more details about how to identify if a JAVA asynchronous technology is automatic instrumentations or not ?

@jeanbisutti
Copy link
Member

@trask
Copy link
Member

trask commented Mar 5, 2024

hi @Charlie441324219, context is intentionally not propagated to manually created threads, see open-telemetry/opentelemetry-java-instrumentation#2527, other cases are generally handled

@Charlie441324219
Copy link
Author

Thank you @jeanbisutti @trask ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants