Datadog how to implement ddtrace on Flask application?

Viewed 1976

I was able to follow these instructions carefully and thoroughly https://docs.datadoghq.com/tracing/setup/python/,

I successfully installed DataDog Agent following this guide https://docs.datadoghq.com/tracing/setup/,

I was also able to install MacOS tracer since it is required for mac user: https://github.com/DataDog/datadog-trace-agent#run-on-osx,

I enabled apm_config in the configuration file found here: https://docs.datadoghq.com/agent/faq/agent-configuration-files/?tab=agentv6#agent-main-configuration-file

apm_config:
  enabled: true

I leave the env: none since I only need to run it in on development/debug mode.

Now Im currently on the step 4: Instrument your application guide for Flask and here the steps I took:

  1. $ pip install ddtrace
  2. Add integration for flask:

    import blinker as _
    
    from ddtrace import tracer
    from ddtrace.contrib.flask import TraceMiddleware
    
    app = Flask(__name__, static_folder='../public/', static_url_path='')
    
    traced_app = TraceMiddleware(app, tracer, service="my-app", distributed_tracing=True)
    

And also my application runs in a docker container and this is what I get from the output log:

ERROR:ddtrace.writer:cannot send services to localhost:8126

Additional Information

On the tracer agent:

INFO (main.go:161) - trace-agent running on host CPUZ124.local
INFO (receiver.go:140) - listening for traces at http://localhost:8126
1 Answers

You installed the Datadog agent & trace agent on a Mac, listening on localhost.

You installed the flask application and ddtrace library in a docker container on a linux vm sending traffic to localhost.

Those two localhosts are describing two different machines. The easiest option is going to be running both the Agent & flask app on the Mac, or running both in docker. The latter is most similar to an eventual production deployment. Do that.

Related