pip install jaeger-client
from jaeger_client import Tracer, SpanContext, Config
# Replace these with your actual configuration
SERVICE_NAME = "your-application-name"
COLLECTOR_HOST = "localhost"
COLLECTOR_PORT = 5778
def configure_tracer():
config = Config(
config={
"sampler": {
"type": "const",
"param": 1, # Sample all requests (optional, adjust as needed)
},
"local_agent": {
"reporting_host": COLLECTOR_HOST,
"reporting_port": COLLECTOR_PORT,
},
"service_name": SERVICE_NAME,
}
)
return Tracer(config=config, name=SERVICE_NAME)
tracer = configure_tracer() # Initialize tracer globally
def traced_login(username, password):
with tracer.start_span("login", tags={"username": username}) as span:
# Simulate login logic (replace with your actual implementation)
login_successful = username == "user1" and password == "correct_password" # Don't use real passwords
# Don't log the password! (Security concern)
span.set_tag("login_successful", str(login_successful))
return login_successful # Return the login result
# Example usage (replace with your actual logic)
def handle_login_request(username, password):
login_result = traced_login(username, password)
if login_result:
print(f"Login successful for user: {username}")
else:
print("Login failed!")
if __name__ == "__main__":
handle_login_request("user1", "correct_password") # Replace with actual values
logs payload
doesn't log payload