---
title: "POST /v2/{+name}/traces:batchWrite"
method: POST
path: "/v2/{+name}/traces:batchWrite"
tags: ["projects"]
---

# POST /v2/{+name}/traces:batchWrite

`POST /v2/{+name}/traces:batchWrite`

Batch writes new spans to new or existing traces. You cannot update existing spans. If a span ID already exists, an additional copy of the span will be stored.

## Path parameters

- `name` string, required

## Request body

- BatchWriteSpansRequest — The request message for the `BatchWriteSpans` method.
  - `spans` Span[] — Required. A list of new spans. The span names must not match existing spans, otherwise the results are undefined.
    - `status` Status — The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).
      - `code` integer — The status code, which should be an enum value of google.rpc.Code.
      - `message` string — A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the google.rpc.Status.details field, or localized by the client.
      - `details` object[] — A list of messages that carry the error details. There is a common set of message types for APIs to use.
    - `stackTrace` StackTrace — A call stack appearing in a trace.
      - `stackFrames` StackFrames — A collection of stack frames, which can be truncated.
        - `droppedFramesCount` integer — The number of stack frames that were dropped because there were too many stack frames. If this value is 0, then no stack frames were dropped.
        - `frame` StackFrame[] — Stack frames in this call stack.
          - `functionName` TruncatableString — Represents a string that might be shortened to a specified length.
            - `value` string — The shortened string. For example, if the original string is 500 bytes long and the limit of the string is 128 bytes, then `value` contains the first 128 bytes of the 500-byte string. Truncation always happens on a UTF8 character boundary. If there are multi-byte characters in the string, then the length of the shortened string might be less than the size limit.
            - `truncatedByteCount` integer — The number of bytes removed from the original string. If this value is 0, then the string was not shortened.
          - `fileName` TruncatableString — Represents a string that might be shortened to a specified length.
            - `value` string — The shortened string. For example, if the original string is 500 bytes long and the limit of the string is 128 bytes, then `value` contains the first 128 bytes of the 500-byte string. Truncation always happens on a UTF8 character boundary. If there are multi-byte characters in the string, then the length of the shortened string might be less than the size limit.
            - `truncatedByteCount` integer — The number of bytes removed from the original string. If this value is 0, then the string was not shortened.
          - `sourceVersion` TruncatableString — Represents a string that might be shortened to a specified length.
            - `value` string — The shortened string. For example, if the original string is 500 bytes long and the limit of the string is 128 bytes, then `value` contains the first 128 bytes of the 500-byte string. Truncation always happens on a UTF8 character boundary. If there are multi-byte characters in the string, then the length of the shortened string might be less than the size limit.
            - `truncatedByteCount` integer — The number of bytes removed from the original string. If this value is 0, then the string was not shortened.
          - `lineNumber` string, int64 — The line number in `file_name` where the function call appears.
          - `columnNumber` string, int64 — The column number where the function call appears, if available. This is important in JavaScript because of its anonymous functions.
          - `loadModule` Module — Binary module.
            - `module` TruncatableString — Represents a string that might be shortened to a specified length.
              - …
            - `buildId` TruncatableString — Represents a string that might be shortened to a specified length.
              - …
          - `originalFunctionName` TruncatableString — Represents a string that might be shortened to a specified length.
            - `value` string — The shortened string. For example, if the original string is 500 bytes long and the limit of the string is 128 bytes, then `value` contains the first 128 bytes of the 500-byte string. Truncation always happens on a UTF8 character boundary. If there are multi-byte characters in the string, then the length of the shortened string might be less than the size limit.
            - `truncatedByteCount` integer — The number of bytes removed from the original string. If this value is 0, then the string was not shortened.
      - `stackTraceHashId` string, int64 — The hash ID is used to conserve network bandwidth for duplicate stack traces within a single trace. Often multiple spans will have identical stack traces. The first occurrence of a stack trace should contain both the `stackFrame` content and a value in `stackTraceHashId`. Subsequent spans within the same request can refer to that stack trace by only setting `stackTraceHashId`.
    - `timeEvents` TimeEvents — A collection of `TimeEvent`s. A `TimeEvent` is a time-stamped annotation on the span, consisting of either user-supplied key:value pairs, or details of a message sent/received between Spans.
      - `timeEvent` TimeEvent[] — A collection of `TimeEvent`s.
        - `time` string, google-datetime — The timestamp indicating the time the event occurred.
        - `annotation` Annotation — Text annotation with a set of attributes.
          - `description` TruncatableString — Represents a string that might be shortened to a specified length.
            - `value` string — The shortened string. For example, if the original string is 500 bytes long and the limit of the string is 128 bytes, then `value` contains the first 128 bytes of the 500-byte string. Truncation always happens on a UTF8 character boundary. If there are multi-byte characters in the string, then the length of the shortened string might be less than the size limit.
            - `truncatedByteCount` integer — The number of bytes removed from the original string. If this value is 0, then the string was not shortened.
          - `attributes` Attributes — A set of attributes as key-value pairs.
            - `attributeMap` object — A set of attributes. Each attribute's key can be up to 128 bytes long. The value can be a string up to 256 bytes, a signed 64-bit integer, or the boolean values `true` or `false`. For example: "/instance_id": { "string_value": { "value": "my-instance" } } "/http/request_bytes": { "int_value": 300 } "example.com/myattribute": { "bool_value": false }
            - `droppedAttributesCount` integer — The number of attributes that were discarded. Attributes can be discarded because their keys are too long or because there are too many attributes. If this value is 0 then all attributes are valid.
        - `messageEvent` MessageEvent — An event describing a message sent/received between Spans.
          - `id` string, int64 — An identifier for the MessageEvent's message that can be used to match `SENT` and `RECEIVED` MessageEvents.
          - `type` 'TYPE_UNSPECIFIED' | 'SENT' | 'RECEIVED' — Type of MessageEvent. Indicates whether the message was sent or received.
          - `compressedSizeBytes` string, int64 — The number of compressed bytes sent or received. If missing, the compressed size is assumed to be the same size as the uncompressed size.
          - `uncompressedSizeBytes` string, int64 — The number of uncompressed bytes sent or received.
      - `droppedAnnotationsCount` integer — The number of dropped annotations in all the included time events. If the value is 0, then no annotations were dropped.
      - `droppedMessageEventsCount` integer — The number of dropped message events in all the included time events. If the value is 0, then no message events were dropped.
    - `sameProcessAsParentSpan` boolean — Optional. Set this parameter to indicate whether this span is in the same process as its parent. If you do not set this parameter, Trace is unable to take advantage of this helpful information.
    - `spanKind` 'SPAN_KIND_UNSPECIFIED' | 'INTERNAL' | 'SERVER' | 'CLIENT' | 'PRODUCER' | 'CONSUMER' — Optional. Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `CLIENT` (caller) and `SERVER` (callee) to identify an RPC call.
    - `startTime` string, google-datetime — Required. The start time of the span. On the client side, this is the time kept by the local machine where the span execution starts. On the server side, this is the time when the server's application handler starts running.
    - `spanId` string — Required. The `[SPAN_ID]` portion of the span's resource name.
    - `endTime` string, google-datetime — Required. The end time of the span. On the client side, this is the time kept by the local machine where the span execution ends. On the server side, this is the time when the server application handler stops running.
    - `parentSpanId` string — The `[SPAN_ID]` of this span's parent span. If this is a root span, then this field must be empty.
    - `links` Links — A collection of links, which are references from this span to a span in the same or different trace.
      - `droppedLinksCount` integer — The number of dropped links after the maximum size was enforced. If this value is 0, then no links were dropped.
      - `link` Link[] — A collection of links.
        - `spanId` string — The `[SPAN_ID]` for a span within a trace.
        - `attributes` Attributes — A set of attributes as key-value pairs.
          - `attributeMap` object — A set of attributes. Each attribute's key can be up to 128 bytes long. The value can be a string up to 256 bytes, a signed 64-bit integer, or the boolean values `true` or `false`. For example: "/instance_id": { "string_value": { "value": "my-instance" } } "/http/request_bytes": { "int_value": 300 } "example.com/myattribute": { "bool_value": false }
          - `droppedAttributesCount` integer — The number of attributes that were discarded. Attributes can be discarded because their keys are too long or because there are too many attributes. If this value is 0 then all attributes are valid.
        - `traceId` string — The `[TRACE_ID]` for a trace within a project.
        - `type` 'TYPE_UNSPECIFIED' | 'CHILD_LINKED_SPAN' | 'PARENT_LINKED_SPAN' — The relationship of the current span relative to the linked span.
    - `attributes` Attributes — A set of attributes as key-value pairs.
      - `attributeMap` object — A set of attributes. Each attribute's key can be up to 128 bytes long. The value can be a string up to 256 bytes, a signed 64-bit integer, or the boolean values `true` or `false`. For example: "/instance_id": { "string_value": { "value": "my-instance" } } "/http/request_bytes": { "int_value": 300 } "example.com/myattribute": { "bool_value": false }
      - `droppedAttributesCount` integer — The number of attributes that were discarded. Attributes can be discarded because their keys are too long or because there are too many attributes. If this value is 0 then all attributes are valid.
    - `name` string — Required. The resource name of the span in the following format: * `projects/[PROJECT_ID]/traces/[TRACE_ID]/spans/[SPAN_ID]` `[TRACE_ID]` is a unique identifier for a trace within a project; it is a 32-character hexadecimal encoding of a 16-byte array. It should not be zero. `[SPAN_ID]` is a unique identifier for a span within a trace; it is a 16-character hexadecimal encoding of an 8-byte array. It should not be zero. .
    - `displayName` TruncatableString — Represents a string that might be shortened to a specified length.
      - `value` string — The shortened string. For example, if the original string is 500 bytes long and the limit of the string is 128 bytes, then `value` contains the first 128 bytes of the 500-byte string. Truncation always happens on a UTF8 character boundary. If there are multi-byte characters in the string, then the length of the shortened string might be less than the size limit.
      - `truncatedByteCount` integer — The number of bytes removed from the original string. If this value is 0, then the string was not shortened.
    - `childSpanCount` integer — Optional. The number of child spans that were generated while this span was active. If set, allows implementation to detect missing child spans.

## Response `200`

Successful response

---

[API](https://skmtc.dev/google/apis/cloudtrace.md) · [All operations](https://skmtc.dev/google/apis/cloudtrace/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/google/cloudtrace/revisions/8613b92386c9/schema)
