Syntax
Public interface ISpan
Provides access to span-specific methods in the New Relic API.
Description
Provides access to span-specific methods in the New Relic .NET agent API. To obtain a reference to ISpan
, use:
- The
CurrentSpan
property onIAgent
(Recommended). - The
CurrentSpan
property onITransaction
.
This section contains descriptions and parameters of ISpan
methods:
Name | Description |
---|---|
Add contextual information from your application to the current span in form of attributes. | |
Changes the name of the current span/segment/metrics that will be reported to New Relic. |
AddCustomAttribute
Adds contextual information about your application to the current span in the form of attributes.
This method requires .NET agent version and .NET agent API version 8.25 or higher.
Syntax
ISpan AddCustomAttribute(string key, object value)
Parameters
Parameter | Description |
---|---|
string | Identifies the information being reported. Also known as the name.
|
object | The value being reported. |
Returns
A reference to the current span.
Usage considerations
For details about supported data types, see the Custom Attributes guide.
Examples
IAgent agent = NewRelic.Api.Agent.NewRelic.GetAgent(); ISpan currentSpan = agent.CurrentSpan;
currentSpan .AddCustomAttribute("customerName","Bob Smith") .AddCustomAttribute("currentAge",31) .AddCustomAttribute("birthday", new DateTime(2000, 02, 14)) .AddCustomAttribute("waitTime", TimeSpan.FromMilliseconds(93842));
SetName
Changes the name of the current segment/span that will be reported to New Relic. For segments/spans resulting from custom instrumentation, the metric name reported to New Relic will be altered as well.
This method requires .NET agent version and .NET agent API version 10.1.0 or higher.
Syntax
ISpan SetName(string name)
Parameters
Parameter | Description |
---|---|
string | The new name for the span/segment. |
Returns
A reference to the current span.
Examples
[Trace]public void MyTracedMethod(){ IAgent agent = NewRelic.Api.Agent.NewRelic.GetAgent(); ISpan currentSpan = agent.CurrentSpan;
currentSpan.SetName("MyCustomName");