Skip to content

Instantly share code, notes, and snippets.

@jaycdave88
Last active August 17, 2023 15:49
Show Gist options
  • Save jaycdave88/3933799cdf02f9454651ed765de32e14 to your computer and use it in GitHub Desktop.
Save jaycdave88/3933799cdf02f9454651ed765de32e14 to your computer and use it in GitHub Desktop.
Python code to inject the trace_id to be picked-up from the RUM SDK for Initial Document Load
import time
from ddtrace import tracer
from flask import Flask
app = Flask(__name__)
@app.get("/")
def index():
comment = ""
span = tracer.current_span()
if span:
comment = (
f"<!-- DATADOG;trace-id={span.trace_id};trace-time={int(time.time() * 1000 )} -->"
)
return f"{comment}<html><head></head><body><h1>Hello, World!</h1></body></html>"
if __name__ == "__main__":
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment