# Get spans by project_name or project_id and optionally by trace_id and/or type

GET http://localhost:5173/api/v1/private/spans

Get spans by project_name or project_id and optionally by trace_id and/or type

Reference: https://www.comet.com/docs/opik/reference/rest-api/spans/get-spans-by-project

## OpenAPI Specification

```yaml
openapi: 3.1.1
info:
  title: >-
    Get spans by project_name or project_id and optionally by trace_id and/or
    type
  version: endpoint_spans.getSpansByProject
paths:
  /v1/private/spans:
    get:
      operationId: get-spans-by-project
      summary: >-
        Get spans by project_name or project_id and optionally by trace_id
        and/or type
      description: >-
        Get spans by project_name or project_id and optionally by trace_id
        and/or type
      tags:
        - - subpackage_spans
      parameters:
        - name: page
          in: query
          required: false
          schema:
            type: integer
            default: 1
        - name: size
          in: query
          required: false
          schema:
            type: integer
            default: 10
        - name: project_name
          in: query
          required: false
          schema:
            type: string
        - name: project_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: trace_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
        - name: type
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/V1PrivateSpansGetParametersType'
        - name: filters
          in: query
          required: false
          schema:
            type: string
        - name: truncate
          in: query
          required: false
          schema:
            type: boolean
            default: false
        - name: strip_attachments
          in: query
          required: false
          schema:
            type: boolean
            default: false
        - name: sorting
          in: query
          required: false
          schema:
            type: string
        - name: exclude
          in: query
          required: false
          schema:
            type: string
        - name: from_time
          in: query
          required: false
          schema:
            type: string
            format: date-time
        - name: to_time
          in: query
          required: false
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: Spans resource
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SpanPage_Public'
components:
  schemas:
    V1PrivateSpansGetParametersType:
      type: string
      enum:
        - value: general
        - value: tool
        - value: llm
        - value: guardrail
    SpanPublicType:
      type: string
      enum:
        - value: general
        - value: tool
        - value: llm
        - value: guardrail
    JsonListStringPublicOneOf1Items:
      type: object
      properties: {}
    JsonListStringPublic1:
      type: array
      items:
        $ref: '#/components/schemas/JsonListStringPublicOneOf1Items'
    JsonListString_Public:
      oneOf:
        - type: object
          additionalProperties:
            description: Any type
        - $ref: '#/components/schemas/JsonListStringPublic1'
        - type: string
    ErrorInfo_Public:
      type: object
      properties:
        exception_type:
          type: string
        message:
          type: string
        traceback:
          type: string
      required:
        - exception_type
        - traceback
    FeedbackScorePublicSource:
      type: string
      enum:
        - value: ui
        - value: sdk
        - value: online_scoring
    ValueEntryPublicSource:
      type: string
      enum:
        - value: ui
        - value: sdk
        - value: online_scoring
    ValueEntry_Public:
      type: object
      properties:
        value:
          type: number
          format: double
        reason:
          type: string
        category_name:
          type: string
        source:
          $ref: '#/components/schemas/ValueEntryPublicSource'
        last_updated_at:
          type: string
          format: date-time
        span_type:
          type: string
        span_id:
          type: string
    FeedbackScore_Public:
      type: object
      properties:
        name:
          type: string
        category_name:
          type: string
        value:
          type: number
          format: double
        reason:
          type: string
        source:
          $ref: '#/components/schemas/FeedbackScorePublicSource'
        created_at:
          type: string
          format: date-time
        last_updated_at:
          type: string
          format: date-time
        created_by:
          type: string
        last_updated_by:
          type: string
        value_by_author:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/ValueEntry_Public'
      required:
        - name
        - value
        - source
    Comment_Public:
      type: object
      properties:
        id:
          type: string
          format: uuid
        text:
          type: string
        created_at:
          type: string
          format: date-time
        last_updated_at:
          type: string
          format: date-time
        created_by:
          type: string
        last_updated_by:
          type: string
      required:
        - text
    Span_Public:
      type: object
      properties:
        id:
          type: string
          format: uuid
        project_name:
          type: string
          description: If null, the default project is used
        project_id:
          type: string
          format: uuid
        trace_id:
          type: string
          format: uuid
        parent_span_id:
          type: string
          format: uuid
        name:
          type: string
        type:
          $ref: '#/components/schemas/SpanPublicType'
        start_time:
          type: string
          format: date-time
        end_time:
          type: string
          format: date-time
        input:
          $ref: '#/components/schemas/JsonListString_Public'
        output:
          $ref: '#/components/schemas/JsonListString_Public'
        metadata:
          $ref: '#/components/schemas/JsonListString_Public'
        model:
          type: string
        provider:
          type: string
        tags:
          type: array
          items:
            type: string
        usage:
          type: object
          additionalProperties:
            type: integer
        error_info:
          $ref: '#/components/schemas/ErrorInfo_Public'
        created_at:
          type: string
          format: date-time
        last_updated_at:
          type: string
          format: date-time
        created_by:
          type: string
        last_updated_by:
          type: string
        feedback_scores:
          type: array
          items:
            $ref: '#/components/schemas/FeedbackScore_Public'
        comments:
          type: array
          items:
            $ref: '#/components/schemas/Comment_Public'
        total_estimated_cost:
          type: number
          format: double
        total_estimated_cost_version:
          type: string
        duration:
          type: number
          format: double
          description: >-
            Duration in milliseconds as a decimal number to support
            sub-millisecond precision
      required:
        - start_time
    SpanPage_Public:
      type: object
      properties:
        page:
          type: integer
        size:
          type: integer
        total:
          type: integer
          format: int64
        content:
          type: array
          items:
            $ref: '#/components/schemas/Span_Public'
        sortableBy:
          type: array
          items:
            type: string

```

## SDK Code Examples

```python
import requests

url = "http://localhost:5173/api/v1/private/spans"

response = requests.get(url)

print(response.json())
```

```javascript
const url = 'http://localhost:5173/api/v1/private/spans';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:5173/api/v1/private/spans"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("http://localhost:5173/api/v1/private/spans")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

```java
HttpResponse<String> response = Unirest.get("http://localhost:5173/api/v1/private/spans")
  .asString();
```

```php
<?php

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'http://localhost:5173/api/v1/private/spans');

echo $response->getBody();
```

```csharp
var client = new RestClient("http://localhost:5173/api/v1/private/spans");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:5173/api/v1/private/spans")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```