Open
Description
Describe your environment
The grequests
module is a wrapper around the requests module to parallelize requests. While using this module, the trace of the HTTP requests are not getting associated with the parent context. I tried with 4 parallel requests and all of them have different trace ids.
Steps to reproduce
Please see the following code snippet to reproduce the problem.
import grequests
from opentelemetry import trace
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
SimpleSpanProcessor,
)
from opentelemetry.sdk.trace import sampling
tracer_provider = TracerProvider()
tracer_provider.sampler = sampling.ParentBased(sampling.ALWAYS_ON)
trace.set_tracer_provider(tracer_provider)
trace.get_tracer_provider().add_span_processor(
SimpleSpanProcessor(ConsoleSpanExporter())
)
RequestsInstrumentor().instrument()
urls = [
'http://www.heroku.com',
'http://www.facebook.com',
'http://www.instagram.com',
'http://www.google.com',
]
def hello():
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("example-request"):
rs = (grequests.get(u) for u in urls)
print(grequests.map(rs))
hello()
What is the expected behavior?
Since requests are created within the parent's context, I expect to see all requests to have the same trace id.
What is the actual behavior?
{
"name": "HTTP GET",
"context": {
"trace_id": "0x4b1ec3b31c6450c0be8964c551b44c08",
"span_id": "0x29c0d897f72a984a",
"trace_state": "[]"
},
"kind": "SpanKind.CLIENT",
"parent_id": null,
"start_time": "2021-06-23T19:21:42.221516Z",
"end_time": "2021-06-23T19:21:42.485323Z",
"status": {
"status_code": "UNSET"
},
"attributes": {
"http.method": "GET",
"http.url": "http://www.google.com",
"http.status_code": 200,
"http.status_text": "OK"
},
"events": [],
"links": [],
"resource": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.0.0",
"service.name": "unknown_service"
}
}
{
"name": "HTTP GET",
"context": {
"trace_id": "0x69ca27f26d5c8b03f8d55be73cb48fc4",
"span_id": "0x56115bec426ad4af",
"trace_state": "[]"
},
"kind": "SpanKind.CLIENT",
"parent_id": null,
"start_time": "2021-06-23T19:21:42.219740Z",
"end_time": "2021-06-23T19:21:43.040657Z",
"status": {
"status_code": "UNSET"
},
"attributes": {
"http.method": "GET",
"http.url": "http://www.facebook.com",
"http.status_code": 200,
"http.status_text": "OK"
},
"events": [],
"links": [],
"resource": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.0.0",
"service.name": "unknown_service"
}
}
{
"name": "HTTP GET",
"context": {
"trace_id": "0x2276dda25bd767a001cd3e1c6c978684",
"span_id": "0xcc7f68b04b3a6533",
"trace_state": "[]"
},
"kind": "SpanKind.CLIENT",
"parent_id": null,
"start_time": "2021-06-23T19:21:42.220744Z",
"end_time": "2021-06-23T19:21:43.443545Z",
"status": {
"status_code": "UNSET"
},
"attributes": {
"http.method": "GET",
"http.url": "http://www.instagram.com",
"http.status_code": 200,
"http.status_text": "OK"
},
"events": [],
"links": [],
"resource": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.0.0",
"service.name": "unknown_service"
}
}
{
"name": "HTTP GET",
"context": {
"trace_id": "0x990ec0f55354eedd5fc20d44419d45f9",
"span_id": "0x048729577c83d30b",
"trace_state": "[]"
},
"kind": "SpanKind.CLIENT",
"parent_id": null,
"start_time": "2021-06-23T19:21:42.205409Z",
"end_time": "2021-06-23T19:21:43.943165Z",
"status": {
"status_code": "UNSET"
},
"attributes": {
"http.method": "GET",
"http.url": "http://www.heroku.com",
"http.status_code": 200,
"http.status_text": "OK"
},
"events": [],
"links": [],
"resource": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.0.0",
"service.name": "unknown_service"
}
}
[<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]
{
"name": "example-request",
"context": {
"trace_id": "0x8c0e7cfeb2f35ef8ac583f5ca4177b44",
"span_id": "0x3098a0cd8e7eea49",
"trace_state": "[]"
},
"kind": "SpanKind.INTERNAL",
"parent_id": null,
"start_time": "2021-06-23T19:21:42.196124Z",
"end_time": "2021-06-23T19:21:43.946074Z",
"status": {
"status_code": "UNSET"
},
"attributes": {},
"events": [],
"links": [],
"resource": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.0.0",
"service.name": "unknown_service"
}
}
Additional context
Add any other context about the problem here.