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

Flask with Pymongo Instrumentation is not consistent and reflects wrong service name #72

Closed
Tracked by #100
yossicohn-hs opened this issue Mar 7, 2021 · 7 comments
Assignees
Labels

Comments

@yossicohn-hs
Copy link

yossicohn-hs commented Mar 7, 2021

When Running Flask(or FastAPI) instrumentation with Pymongo instrumentation, we get Grafana different visualization.
A function residing under a Flask would once get a "service" with proper Flask value and on the other occasion it would get the wrong value of "MongoDB_Database"

Simulation,
Step 1 - create flask image, using Flask and Pymongo instrumentation
Step 2 - run the image with was collector (via docker-compose)
step 3 - Grafana Traces seem different than AWS XRay

In the code below 2 functions should be under the Flask service (as defined by the OTEL_RESOURCE_ATTRIBUTES service.name in the service Environment Variable) function do_my_function and the do_my_second_function somehow
the result is with the service (and coloring ) with the MongoDB_Database vs the Flask service.
This happens in most of the traces while avery few get the proper service name and coloring

The python code is:

from flask import Flask
from pymongo import MongoClient
from opentelemetry import propagators, trace
from opentelemetry.sdk.extension.aws.trace.propagation.aws_xray_format import (
    AwsXRayFormat,
)
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.extension.aws.trace import AwsXRayIdsGenerator
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.pymongo import PymongoInstrumentor

propagators.set_global_textmap(AwsXRayFormat())
otlp_exporter = OTLPSpanExporter()
span_processor = BatchExportSpanProcessor(otlp_exporter)
trace.set_tracer_provider(
    TracerProvider(
        active_span_processor=span_processor, ids_generator=AwsXRayIdsGenerator()
    )
)


app = Flask(__name__)
FlaskInstrumentor().instrument_app(app)
PymongoInstrumentor().instrument()


def do_my_function():
    span = trace.get_current_span()
    tracer = trace.get_tracer(__name__)
    with tracer.start_as_current_span("do_my_function"):
        x = 2 * 3


def do_my_second_function():
    span = trace.get_current_span()
    tracer = trace.get_tracer(__name__)
    with tracer.start_as_current_span("do_my_second_function"):
        x = 2 * 3


@app.route("/foobar")
def foobar():
    do_my_function()
    client = MongoClient(host=["mongo-flask:27017"])
    db = client["MongoDB_Database"]
    collection = db["MongoDB_Collection"]
    collection.insert_one({"hello": "hi"})
    collection.find_one()
    do_my_second_function()
    return {"message": "PyMongo hello world"}

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=8000)

requirements.txt

pymongo
Flask==1.1.2
opentelemetry-instrumentation-flask==0.17b0
opentelemetry-instrumentation==0.17b0
opentelemetry-instrumentation-requests==0.17b0
opentelemetry-instrumentation-botocore==0.17b0
opentelemetry-instrumentation-wsgi==0.17b0
opentelemetry-exporter-otlp==0.17b0
opentelemetry-sdk-extension-aws==0.17b0
opentelemetry-instrumentation-pymongo==0.17b0
@yossicohn-hs
Copy link
Author

@davkal not sure about the label your set.
Just to make it clear, the issue I opened was that the data is not visualized properly, I don't see the connection to X-Ray here

@davkal
Copy link

davkal commented Apr 8, 2021

Not to worry, this label is needed for our internal triaging tool. But regardless, there is still a possibility that something is off in the x-ray-to-jaeger mapping code that could cause this. If it's a trace viewer issue, then we should reopen this in the grafana repo with the label area/tracing.

@zoltanbedi
Copy link
Member

After some time I was able to replicate the issue. Thanks for the detailed issue.

@zoltanbedi zoltanbedi added type/bug Something isn't working and removed needs investigation labels May 14, 2021
@aocenas aocenas added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. label May 26, 2021
@zoltanbedi zoltanbedi removed their assignment May 26, 2021
@sarahzinger sarahzinger mentioned this issue Feb 11, 2022
6 tasks
@sarahzinger sarahzinger removed their assignment Apr 6, 2022
@sarahzinger sarahzinger self-assigned this Aug 9, 2022
@sarahzinger
Copy link
Member

@yossicohn-hs Hello! Taking a look at this now, apologies for the delay! A few questions:

  • are you still seeing this issue?
  • to clarify is this issue related to Grafana's X-Ray datasource plugin? Or is the issue that the traces you see in Tempo do not look properly formatted?
  • If you are still experiencing this issue, can you tell me what versions of grafana and the xray datasource plugin you're on?

@zoltanbedi, do you recall any additional details on this ticket? Would it make more sense to close and reopen this for the traces team, or does the issue seem to be with the xray datasource plugin?

Thanks so much!

@sarahzinger sarahzinger added needs investigation needs more info Issue needs more information, like query results, dashboard or panel json, grafana version etc and removed priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. needs investigation labels Aug 10, 2022
@zoltanbedi
Copy link
Member

@sarahzinger Oh well, it's been a while. Only thing I can recall is that it took some time to setup the python project but at the end I saw the issue happening. Sadly I can't recall what was the issue there.

@yossicohn-hs
Copy link
Author

@zoltanbedi @sarahzinger I think this is behaving ok now

@zoltanbedi
Copy link
Member

That is awesome! @yossicohn-hs thanks for letting us know!

@sarahzinger sarahzinger added effort/small and removed needs more info Issue needs more information, like query results, dashboard or panel json, grafana version etc labels Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

5 participants