You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are you trying to achieve?
I init a tracerProvider in main process . and then i start a new sub process, i children process i start a span. but the span will not export to the endpoint.
here is my code:
import os
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
OTLPSpanExporter,
)
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from multiprocessing import Process
import multiprocessing as mp
def init_tracer():
resource = Resource.create(
attributes={
"service.name": "api-service",
# If workers are not distinguished within attributes, traces and
# metrics exported from each worker will be indistinguishable. While
# not necessarily an issue for traces, it is confusing for almost
# all metric types. A built-in way to identify a worker is by PID
# but this may lead to high label cardinality. An alternative
# workaround and additional discussion are available here:
# https://github.com/benoitc/gunicorn/issues/1352
"worker": os.getpid(),
}
)
trace.set_tracer_provider(TracerProvider(resource=resource))
# This uses insecure connection for the purpose of example. Please see the
# OTLP Exporter documentation for other options.
span_processor = BatchSpanProcessor(
OTLPSpanExporter(endpoint="http://tempo.mytempo.cn:4318/v1/traces")
)
trace.get_tracer_provider().add_span_processor(span_processor)
def worker_func(name):
info("worker function")
import time
def info(title):
with trace.get_tracer(__name__).start_as_current_span('multi-span') as span:
span.set_attribute("pid", os.getpid())
print(f"info function {title} running, span context : {trace.get_current_span().get_span_context()}")
time.sleep(3)
if __name__ == '__main__':
init_tracer()
print('----------------------')
mp.set_start_method('fork')
p = Process(target=worker_func, args=('bob',))
p.start()
p.join()
What did you expect to see?
i can reinitialize the global TracerProvider, then the BatchSpanProcessor.worker() function will work well in subprocess. Additional context.
i have seen the implementation. it seems the SynchronousMultiSpanProcessor does not be copy when i initialize the TracerProvider in main process and then fork. so when the child process end, the SynchronousMultiSpanProcessor will not call shutdown in child process. and then the BatchSpanProcessor in child process will not call shutdown() function, and so the BatchSpanProcessor.worker() will not be joined by shutdown() function. so it does not work well in my code.
if we have a function that can reinitialize the TracerProvider in child process. it will work well. just like i use a spawn method to new a child process. i can new a TracerProvider in child process.
Add any other context about the problem here. If you followed an existing documentation, please share the link to it.
The text was updated successfully, but these errors were encountered:
What are you trying to achieve?
I init a tracerProvider in main process . and then i start a new sub process, i children process i start a span. but the span will not export to the endpoint.
here is my code:
What did you expect to see?
i can reinitialize the global TracerProvider, then the BatchSpanProcessor.worker() function will work well in subprocess.
Additional context.
i have seen the implementation. it seems the SynchronousMultiSpanProcessor does not be copy when i initialize the TracerProvider in main process and then fork. so when the child process end, the SynchronousMultiSpanProcessor will not call shutdown in child process. and then the BatchSpanProcessor in child process will not call shutdown() function, and so the BatchSpanProcessor.worker() will not be joined by shutdown() function. so it does not work well in my code.
if we have a function that can reinitialize the TracerProvider in child process. it will work well. just like i use a spawn method to new a child process. i can new a TracerProvider in child process.
Add any other context about the problem here. If you followed an existing documentation, please share the link to it.
The text was updated successfully, but these errors were encountered: