@datadog/datadog-api-client
Version:
OpenAPI client for Datadog APIs
248 lines • 14.1 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.APMTraceApi = exports.APMTraceApiResponseProcessor = exports.APMTraceApiRequestFactory = void 0;
const baseapi_1 = require("../../datadog-api-client-common/baseapi");
const configuration_1 = require("../../datadog-api-client-common/configuration");
const http_1 = require("../../datadog-api-client-common/http/http");
const logger_1 = require("../../../logger");
const ObjectSerializer_1 = require("../models/ObjectSerializer");
const exception_1 = require("../../datadog-api-client-common/exception");
class APMTraceApiRequestFactory extends baseapi_1.BaseAPIRequestFactory {
getPrunedTraceByID(traceId, expandSpanId, timeHint, forceSource, includePath, tagInclude, tagExclude, onlyServiceEntrySpans, _options) {
return __awaiter(this, void 0, void 0, function* () {
const _config = _options || this.configuration;
logger_1.logger.warn("Using unstable operation 'getPrunedTraceByID'");
if (!_config.unstableOperations["v2.getPrunedTraceByID"]) {
throw new Error("Unstable operation 'getPrunedTraceByID' is disabled");
}
// verify required parameter 'traceId' is not null or undefined
if (traceId === null || traceId === undefined) {
throw new baseapi_1.RequiredError("traceId", "getPrunedTraceByID");
}
// Path Params
const localVarPath = "/api/v2/pruned_trace/{trace_id}".replace("{trace_id}", encodeURIComponent(String(traceId)));
// Make Request Context
const requestContext = _config
.getServer("v2.APMTraceApi.getPrunedTraceByID")
.makeRequestContext(localVarPath, http_1.HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);
// Query Params
if (expandSpanId !== undefined) {
requestContext.setQueryParam("expand_span_id", ObjectSerializer_1.ObjectSerializer.serialize(expandSpanId, "number", "int64"), "");
}
if (timeHint !== undefined) {
requestContext.setQueryParam("time_hint", ObjectSerializer_1.ObjectSerializer.serialize(timeHint, "number", "int32"), "");
}
if (forceSource !== undefined) {
requestContext.setQueryParam("force_source", ObjectSerializer_1.ObjectSerializer.serialize(forceSource, "string", ""), "");
}
if (includePath !== undefined) {
requestContext.setQueryParam("include_path", ObjectSerializer_1.ObjectSerializer.serialize(includePath, "Array<string>", ""), "multi");
}
if (tagInclude !== undefined) {
requestContext.setQueryParam("tag_include", ObjectSerializer_1.ObjectSerializer.serialize(tagInclude, "Array<string>", ""), "multi");
}
if (tagExclude !== undefined) {
requestContext.setQueryParam("tag_exclude", ObjectSerializer_1.ObjectSerializer.serialize(tagExclude, "Array<string>", ""), "multi");
}
if (onlyServiceEntrySpans !== undefined) {
requestContext.setQueryParam("only_service_entry_spans", ObjectSerializer_1.ObjectSerializer.serialize(onlyServiceEntrySpans, "boolean", ""), "");
}
// Apply auth methods
(0, configuration_1.applySecurityAuthentication)(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
"AuthZ",
]);
return requestContext;
});
}
getTraceByID(traceId, includeFields, _options) {
return __awaiter(this, void 0, void 0, function* () {
const _config = _options || this.configuration;
logger_1.logger.warn("Using unstable operation 'getTraceByID'");
if (!_config.unstableOperations["v2.getTraceByID"]) {
throw new Error("Unstable operation 'getTraceByID' is disabled");
}
// verify required parameter 'traceId' is not null or undefined
if (traceId === null || traceId === undefined) {
throw new baseapi_1.RequiredError("traceId", "getTraceByID");
}
// Path Params
const localVarPath = "/api/v2/trace/{trace_id}".replace("{trace_id}", encodeURIComponent(String(traceId)));
// Make Request Context
const requestContext = _config
.getServer("v2.APMTraceApi.getTraceByID")
.makeRequestContext(localVarPath, http_1.HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json");
requestContext.setHttpConfig(_config.httpConfig);
// Query Params
if (includeFields !== undefined) {
requestContext.setQueryParam("include_fields", ObjectSerializer_1.ObjectSerializer.serialize(includeFields, "Array<string>", ""), "multi");
}
// Apply auth methods
(0, configuration_1.applySecurityAuthentication)(_config, requestContext, [
"apiKeyAuth",
"appKeyAuth",
"AuthZ",
]);
return requestContext;
});
}
}
exports.APMTraceApiRequestFactory = APMTraceApiRequestFactory;
class APMTraceApiResponseProcessor {
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to getPrunedTraceByID
* @throws ApiException if the response code was not in [200, 299]
*/
getPrunedTraceByID(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (response.httpStatusCode === 200) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "PrunedTraceResponse");
return body;
}
if (response.httpStatusCode === 403 ||
response.httpStatusCode === 404 ||
response.httpStatusCode === 504) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "JSONAPIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "APIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "PrunedTraceResponse", "");
return body;
}
const body = (yield response.body.text()) || "";
throw new exception_1.ApiException(response.httpStatusCode, 'Unknown API Status Code!\nBody: "' + body + '"');
});
}
/**
* Unwraps the actual response sent by the server from the response context and deserializes the response content
* to the expected objects
*
* @params response Response returned by the server for a request to getTraceByID
* @throws ApiException if the response code was not in [200, 299]
*/
getTraceByID(response) {
return __awaiter(this, void 0, void 0, function* () {
const contentType = ObjectSerializer_1.ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (response.httpStatusCode === 200) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "TraceResponse");
return body;
}
if (response.httpStatusCode === 403 ||
response.httpStatusCode === 404 ||
response.httpStatusCode === 413) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "JSONAPIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
if (response.httpStatusCode === 429) {
const bodyText = ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType);
let body;
try {
body = ObjectSerializer_1.ObjectSerializer.deserialize(bodyText, "APIErrorResponse");
}
catch (error) {
logger_1.logger.debug(`Got error deserializing error: ${error}`);
throw new exception_1.ApiException(response.httpStatusCode, bodyText);
}
throw new exception_1.ApiException(response.httpStatusCode, body);
}
// Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const body = ObjectSerializer_1.ObjectSerializer.deserialize(ObjectSerializer_1.ObjectSerializer.parse(yield response.body.text(), contentType), "TraceResponse", "");
return body;
}
const body = (yield response.body.text()) || "";
throw new exception_1.ApiException(response.httpStatusCode, 'Unknown API Status Code!\nBody: "' + body + '"');
});
}
}
exports.APMTraceApiResponseProcessor = APMTraceApiResponseProcessor;
class APMTraceApi {
constructor(configuration, requestFactory, responseProcessor) {
this.configuration = configuration;
this.requestFactory =
requestFactory || new APMTraceApiRequestFactory(configuration);
this.responseProcessor =
responseProcessor || new APMTraceApiResponseProcessor();
}
/**
* Retrieve a pruned, hierarchical view of an APM trace by its trace ID.
* The trace is summarized as a tree of spans rooted at the trace root and reduced in size
* to keep rendering large traces in the UI practical.
* This endpoint is rate limited to `60` requests per minute per organization.
* @param param The request object
*/
getPrunedTraceByID(param, options) {
const requestContextPromise = this.requestFactory.getPrunedTraceByID(param.traceId, param.expandSpanId, param.timeHint, param.forceSource, param.includePath, param.tagInclude, param.tagExclude, param.onlyServiceEntrySpans, options);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.getPrunedTraceByID(responseContext);
});
});
}
/**
* Retrieve a full APM trace by its trace ID, including every span in the trace.
* Traces are returned from live storage when available and fall back to longer-term storage.
* This endpoint is rate limited to `60` requests per minute per organization.
* @param param The request object
*/
getTraceByID(param, options) {
const requestContextPromise = this.requestFactory.getTraceByID(param.traceId, param.includeFields, options);
return requestContextPromise.then((requestContext) => {
return this.configuration.httpApi
.send(requestContext)
.then((responseContext) => {
return this.responseProcessor.getTraceByID(responseContext);
});
});
}
}
exports.APMTraceApi = APMTraceApi;
//# sourceMappingURL=APMTraceApi.js.map