< Previous Challenge - Home - Next Challenge >
In Challenge 03, you verified that the Agent Framework automatically generates traces and metrics for your AI agent operations. Now it’s time to add custom instrumentation to capture application-specific insights.
Custom instrumentation allows you to:
By the end of this challenge, you’ll have visibility into both the automatic Agent Framework telemetry and your custom business logic, all flowing to New Relic.
Your goal is to add custom spans, metrics, and structured logging to your travel planning application:
Tool Instrumentation:
By leveraging the above approach you will notice that the Agent Framework automatically instruments tool calls. However, to get more detailed insights, you will manually add spans around each tool function:
get_random_destination, get_weather, get_datetime) with tracer.start_as_current_span() to create custom spansRoute Instrumentation:
Instrument your Flask routes to capture the full request lifecycle. Add spans for request handling, data validation, and response preparation.
Logging Configuration:
Configure structured logging that automatically includes trace context. This allows you to correlate logs with specific spans in New Relic, making it easier to debug issues.
Example: When a user requests a trip plan, you should see:
When you submit a travel request, you should see a complete trace in New Relic showing:
Restart your app again and execute a generate request for a travel plan. Verify that your app appears in New Relic (it can take a few minutes for additional data to appear) as an entity within the Services - OpenTelemetry section. The name of the entity should match the OTEL_SERVICE_NAME you set in the .env file. Dig into Distributed tracing section and look for traces generated by your application. You should see an additional trace group with a name like plan_trip (or similar if you used a different name in for the custom span).

Click into the trace group to see all the individual traces for that group.

Investigate and observe the details of a single trace.

You should see your custom spans (e.g., plan_trip, get_random_destination, etc.) alongside the auto-generated Agent Framework spans. Click into your custom spans to see the attributes you added (e.g., destination names, flight prices, etc.). You should also see any logs that were correlated with those spans.
To complete this challenge successfully, you should be able to:
get_tracer() and get_meter() from Agent Framework for consistency