The current span type. SeeSpanTypefor more information.
Methods
addLabel(key, value)
addLabel(key:string,value:any):void;
Adds a key-value pair as a label to the trace span. The value will be converted to a string if it is not already, and both the key and value may be truncated according to the user's configuration.
Parameters
Name
Description
key
string
The label's key.
value
any
The label's value.
Returns
Type
Description
void
endSpan(timestamp)
endSpan(timestamp?:Date):void;
Ends the span. This method should only be called once.
Parameter
Name
Description
timestamp
Date
A custom span end time; defaults to the time when endSpan was called if not provided.
Returns
Type
Description
void
getTraceContext()
getTraceContext():TraceContext|null;
Gets the current trace context, or null if it can't be retrieved. The trace context.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Interface PluginTypes.Span (8.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [8.0.0 (latest)](/nodejs/docs/reference/trace-agent/latest/trace-agent/plugintypes.span)\n- [7.1.2](/nodejs/docs/reference/trace-agent/7.1.2/trace-agent/plugintypes.span)\n- [7.0.0](/nodejs/docs/reference/trace-agent/7.0.0/trace-agent/plugintypes.span)\n- [5.1.6](/nodejs/docs/reference/trace-agent/5.1.6/trace-agent/plugintypes.span) \nRepresents a trace span.\n\nPackage\n-------\n\n[@google-cloud/trace-agent](../overview.html)\n\nProperties\n----------\n\n### type\n\n readonly type: SpanType;\n\nThe current span type. See `SpanType` for more information.\n\nMethods\n-------\n\n### addLabel(key, value)\n\n addLabel(key: string, value: any): void;\n\nAdds a key-value pair as a label to the trace span. The value will be converted to a string if it is not already, and both the key and value may be truncated according to the user's configuration.\n\n### endSpan(timestamp)\n\n endSpan(timestamp?: Date): void;\n\nEnds the span. This method should only be called once.\n\n### getTraceContext()\n\n getTraceContext(): TraceContext | null;\n\nGets the current trace context, or null if it can't be retrieved. The trace context."]]