|
| 1 | +# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +# This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +# Copyright 2019-Present Datadog, Inc. |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +from typing import Any, Dict, List, Union |
| 7 | + |
| 8 | +from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint |
| 9 | +from datadog_api_client.configuration import Configuration |
| 10 | +from datadog_api_client.model_utils import ( |
| 11 | + UnsetType, |
| 12 | + unset, |
| 13 | +) |
| 14 | +from datadog_api_client.v2.model.pruned_trace_response import PrunedTraceResponse |
| 15 | +from datadog_api_client.v2.model.trace_response import TraceResponse |
| 16 | + |
| 17 | + |
| 18 | +class APMTraceApi: |
| 19 | + """ |
| 20 | + Retrieve full or pruned APM traces by trace ID. |
| 21 | + """ |
| 22 | + |
| 23 | + def __init__(self, api_client=None): |
| 24 | + if api_client is None: |
| 25 | + api_client = ApiClient(Configuration()) |
| 26 | + self.api_client = api_client |
| 27 | + |
| 28 | + self._get_pruned_trace_by_id_endpoint = _Endpoint( |
| 29 | + settings={ |
| 30 | + "response_type": (PrunedTraceResponse,), |
| 31 | + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], |
| 32 | + "endpoint_path": "/api/v2/pruned_trace/{trace_id}", |
| 33 | + "operation_id": "get_pruned_trace_by_id", |
| 34 | + "http_method": "GET", |
| 35 | + "version": "v2", |
| 36 | + }, |
| 37 | + params_map={ |
| 38 | + "trace_id": { |
| 39 | + "required": True, |
| 40 | + "openapi_types": (str,), |
| 41 | + "attribute": "trace_id", |
| 42 | + "location": "path", |
| 43 | + }, |
| 44 | + "expand_span_id": { |
| 45 | + "openapi_types": (int,), |
| 46 | + "attribute": "expand_span_id", |
| 47 | + "location": "query", |
| 48 | + }, |
| 49 | + "time_hint": { |
| 50 | + "validation": { |
| 51 | + "inclusive_maximum": 2147483647, |
| 52 | + }, |
| 53 | + "openapi_types": (int,), |
| 54 | + "attribute": "time_hint", |
| 55 | + "location": "query", |
| 56 | + }, |
| 57 | + "force_source": { |
| 58 | + "openapi_types": (str,), |
| 59 | + "attribute": "force_source", |
| 60 | + "location": "query", |
| 61 | + }, |
| 62 | + "include_path": { |
| 63 | + "openapi_types": ([str],), |
| 64 | + "attribute": "include_path", |
| 65 | + "location": "query", |
| 66 | + "collection_format": "multi", |
| 67 | + }, |
| 68 | + "tag_include": { |
| 69 | + "openapi_types": ([str],), |
| 70 | + "attribute": "tag_include", |
| 71 | + "location": "query", |
| 72 | + "collection_format": "multi", |
| 73 | + }, |
| 74 | + "tag_exclude": { |
| 75 | + "openapi_types": ([str],), |
| 76 | + "attribute": "tag_exclude", |
| 77 | + "location": "query", |
| 78 | + "collection_format": "multi", |
| 79 | + }, |
| 80 | + "only_service_entry_spans": { |
| 81 | + "openapi_types": (bool,), |
| 82 | + "attribute": "only_service_entry_spans", |
| 83 | + "location": "query", |
| 84 | + }, |
| 85 | + }, |
| 86 | + headers_map={ |
| 87 | + "accept": ["application/json"], |
| 88 | + }, |
| 89 | + api_client=api_client, |
| 90 | + ) |
| 91 | + |
| 92 | + self._get_trace_by_id_endpoint = _Endpoint( |
| 93 | + settings={ |
| 94 | + "response_type": (TraceResponse,), |
| 95 | + "auth": ["apiKeyAuth", "appKeyAuth", "AuthZ"], |
| 96 | + "endpoint_path": "/api/v2/trace/{trace_id}", |
| 97 | + "operation_id": "get_trace_by_id", |
| 98 | + "http_method": "GET", |
| 99 | + "version": "v2", |
| 100 | + }, |
| 101 | + params_map={ |
| 102 | + "trace_id": { |
| 103 | + "required": True, |
| 104 | + "openapi_types": (str,), |
| 105 | + "attribute": "trace_id", |
| 106 | + "location": "path", |
| 107 | + }, |
| 108 | + "include_fields": { |
| 109 | + "openapi_types": ([str],), |
| 110 | + "attribute": "include_fields", |
| 111 | + "location": "query", |
| 112 | + "collection_format": "multi", |
| 113 | + }, |
| 114 | + }, |
| 115 | + headers_map={ |
| 116 | + "accept": ["application/json"], |
| 117 | + }, |
| 118 | + api_client=api_client, |
| 119 | + ) |
| 120 | + |
| 121 | + def get_pruned_trace_by_id( |
| 122 | + self, |
| 123 | + trace_id: str, |
| 124 | + *, |
| 125 | + expand_span_id: Union[int, UnsetType] = unset, |
| 126 | + time_hint: Union[int, UnsetType] = unset, |
| 127 | + force_source: Union[str, UnsetType] = unset, |
| 128 | + include_path: Union[List[str], UnsetType] = unset, |
| 129 | + tag_include: Union[List[str], UnsetType] = unset, |
| 130 | + tag_exclude: Union[List[str], UnsetType] = unset, |
| 131 | + only_service_entry_spans: Union[bool, UnsetType] = unset, |
| 132 | + ) -> PrunedTraceResponse: |
| 133 | + """Get a pruned trace by ID. |
| 134 | +
|
| 135 | + Retrieve a pruned, hierarchical view of an APM trace by its trace ID. |
| 136 | + The trace is summarized as a tree of spans rooted at the trace root and reduced in size |
| 137 | + to keep rendering large traces in the UI practical. |
| 138 | + This endpoint is rate limited to ``60`` requests per minute per organization. |
| 139 | +
|
| 140 | + :param trace_id: The trace ID. Accepts either a 32-character hexadecimal string (128-bit trace ID) |
| 141 | + or a decimal string of up to 39 digits. |
| 142 | + :type trace_id: str |
| 143 | + :param expand_span_id: Span ID to expand and preserve in the pruned tree even when its branch would |
| 144 | + normally be summarized. |
| 145 | + :type expand_span_id: int, optional |
| 146 | + :param time_hint: Optional Unix time hint, in seconds, used to optimize the lookup of the trace |
| 147 | + in long-term storage. |
| 148 | + :type time_hint: int, optional |
| 149 | + :param force_source: Force the trace to be loaded from a specific source. When unset, the API picks |
| 150 | + the source automatically. |
| 151 | + :type force_source: str, optional |
| 152 | + :param include_path: Restrict the pruned tree to spans matching the given ``key:value`` pairs. |
| 153 | + Values may be passed as repeated query parameters. |
| 154 | + :type include_path: [str], optional |
| 155 | + :param tag_include: Regex patterns of tag keys whose values must be included in the pruned spans. |
| 156 | + Values may be passed as repeated query parameters. |
| 157 | + :type tag_include: [str], optional |
| 158 | + :param tag_exclude: Regex patterns of tag keys whose values must be excluded from the pruned spans. |
| 159 | + Values may be passed as repeated query parameters. |
| 160 | + :type tag_exclude: [str], optional |
| 161 | + :param only_service_entry_spans: When set to ``true`` , only service entry spans are included in the pruned tree. |
| 162 | + :type only_service_entry_spans: bool, optional |
| 163 | + :rtype: PrunedTraceResponse |
| 164 | + """ |
| 165 | + kwargs: Dict[str, Any] = {} |
| 166 | + kwargs["trace_id"] = trace_id |
| 167 | + |
| 168 | + if expand_span_id is not unset: |
| 169 | + kwargs["expand_span_id"] = expand_span_id |
| 170 | + |
| 171 | + if time_hint is not unset: |
| 172 | + kwargs["time_hint"] = time_hint |
| 173 | + |
| 174 | + if force_source is not unset: |
| 175 | + kwargs["force_source"] = force_source |
| 176 | + |
| 177 | + if include_path is not unset: |
| 178 | + kwargs["include_path"] = include_path |
| 179 | + |
| 180 | + if tag_include is not unset: |
| 181 | + kwargs["tag_include"] = tag_include |
| 182 | + |
| 183 | + if tag_exclude is not unset: |
| 184 | + kwargs["tag_exclude"] = tag_exclude |
| 185 | + |
| 186 | + if only_service_entry_spans is not unset: |
| 187 | + kwargs["only_service_entry_spans"] = only_service_entry_spans |
| 188 | + |
| 189 | + return self._get_pruned_trace_by_id_endpoint.call_with_http_info(**kwargs) |
| 190 | + |
| 191 | + def get_trace_by_id( |
| 192 | + self, |
| 193 | + trace_id: str, |
| 194 | + *, |
| 195 | + include_fields: Union[List[str], UnsetType] = unset, |
| 196 | + ) -> TraceResponse: |
| 197 | + """Get a trace by ID. |
| 198 | +
|
| 199 | + Retrieve a full APM trace by its trace ID, including every span in the trace. |
| 200 | + Traces are returned from live storage when available and fall back to longer-term storage. |
| 201 | + This endpoint is rate limited to ``60`` requests per minute per organization. |
| 202 | +
|
| 203 | + :param trace_id: The trace ID. Accepts either a 32-character hexadecimal string (128-bit trace ID) |
| 204 | + or a decimal string of up to 39 digits. |
| 205 | + :type trace_id: str |
| 206 | + :param include_fields: List of span fields to include in the response. When omitted, every available field is returned. |
| 207 | + Values may be passed as repeated query parameters or as a single comma-separated value. |
| 208 | + :type include_fields: [str], optional |
| 209 | + :rtype: TraceResponse |
| 210 | + """ |
| 211 | + kwargs: Dict[str, Any] = {} |
| 212 | + kwargs["trace_id"] = trace_id |
| 213 | + |
| 214 | + if include_fields is not unset: |
| 215 | + kwargs["include_fields"] = include_fields |
| 216 | + |
| 217 | + return self._get_trace_by_id_endpoint.call_with_http_info(**kwargs) |
0 commit comments