EOL NOTICE
From April 2022, we don't support the C SDK capability. For more details, see our Support Forum post.
Distributed tracing allows you to see the entire journey of your requests throughout a distributed system. The C SDK supports standard distributed tracing with head-based sampling. It doesn't support the feature called Infinite Tracing or W3C Trace context.
The C SDK requires you to manually instrument your C services, unlike the auto-instrumentation of other New Relic agents. This means you need to add some lines to your code to use the C SDK, and then you add an additional configuration to enable distributed tracing.
Here's how to get started:
- Instrument a sample program (recommended): A fast way to get started
- Instrument transactions and HTTP requests
Dica
If you want to get more background before getting started, check out these topics:
- How span sampling works explains distributed tracing options.
- Impacts to APM tells you what to expect if you are a current user but haven't set up distributed tracing.
Instrument a sample program (recommended):
This is a quick way to see how to install the C SDK and instrument a service with standard distributed tracing.
Before you get started with the main steps:
- You'll need a New Relic account to set up distributed tracing. If you don't already have one, you can quickly create a free account. Note that this link will take you to another site to complete the sign-up, but you can return here and follow the setup steps below.
- Make sure you meet the requirements.
Step 1. Identify services
Figure out which services touch your request so you can instrument each of them to send trace data to New Relic.
Step 2. Instrument each service with an APM agent
We have an example of how to install the C SDK and instrument a sample app so it begins to report telemetry to New Relic. Once you understand how it works, you can apply the principles to each of your C services that are involved in your requests. If some of your services use other languages, simply follow the installation steps for those languages.
Before going to the sample service below, note that it will have you create a default newrelic_app_config_t
, but you'll also need to add distributed_tracing.enabled
and set it to true
:
#include <stdlib.h>#include <stdio.h>#include <unistd.h>
/** A standalone example that demonstrates to users how to* configure logging, configure an app, connect an app,* start a transaction and a segment, and cleanly destroy* everything.*/#include "libnewrelic.h"
int main(void) { newrelic_app_t* app; newrelic_txn_t* txn; newrelic_app_config_t* config; newrelic_segment_t* seg;
config = newrelic_create_app_config("<YOUR_APP_NAME>", "9931ae06b54780ab846c16fc602b5778ead3907f"); config->distributed_tracing.enabled = true; ...
To try out the sample program, click here.
Step 3. View traces
After you instrument each of your services with APM agents, generate some traffic in your application so we can capture some traces. Here are some ways to view your traces in the UI:
For more help finding your traces in the UI:
Instrument transactions and HTTP requests
For transactions that occur in multiple services, the distributed trace payload contains information that allows New Relic to stitch them together into a complete transaction trace. However, if New Relic-monitored services are not sending trace context to each other, it will result in incomplete trace details. For more information, see the documentation about passing the distributed tracing API header and the C SDK's distributed tracing documentation on GitHub.
If you want to... | Use this |
---|---|
Create and return a payload to be sent to the called service | |
Accept a payload sent from the first service | This will link these services together in a trace. |
Return a base64-encoded JSON string representation of the payload | This offers the same behavior as |
Accept a base64-encoded string for the payload | This offers the same behavior as |