UNPKG

@kangc/skywalking-backend-js

Version:

The NodeJS agent for Apache SkyWalking

84 lines 4.83 kB
"use strict"; /*! * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var url_1 = require("url"); var ContextManager_1 = tslib_1.__importDefault(require("../trace/context/ContextManager")); var Component_1 = require("../trace/Component"); var Tag_1 = tslib_1.__importDefault(require("../Tag")); var Tracing_pb_1 = require("../proto/language-agent/Tracing_pb"); var ContextCarrier_1 = require("../trace/context/ContextCarrier"); var DummySpan_1 = tslib_1.__importDefault(require("../trace/span/DummySpan")); var AgentConfig_1 = require("../config/AgentConfig"); var AWSLambdaTriggerPlugin_1 = require("./AWSLambdaTriggerPlugin"); var AWSLambdaGatewayAPIHTTP = /** @class */ (function (_super) { tslib_1.__extends(AWSLambdaGatewayAPIHTTP, _super); function AWSLambdaGatewayAPIHTTP() { return _super !== null && _super.apply(this, arguments) || this; } AWSLambdaGatewayAPIHTTP.prototype.start = function (event, context) { var _a, _b, _c, _d, _e; var headers = event.headers; var reqCtx = event.requestContext; var http = reqCtx === null || reqCtx === void 0 ? void 0 : reqCtx.http; var method = http === null || http === void 0 ? void 0 : http.method; var proto = (http === null || http === void 0 ? void 0 : http.protocol) ? http.protocol.split('/')[0].toLowerCase() : headers === null || headers === void 0 ? void 0 : headers['x-forwarded-proto']; var port = (headers === null || headers === void 0 ? void 0 : headers['x-forwarded-port']) || ''; var host = (_a = headers === null || headers === void 0 ? void 0 : headers.host) !== null && _a !== void 0 ? _a : ((reqCtx === null || reqCtx === void 0 ? void 0 : reqCtx.domainName) || ''); var hostport = host ? (port ? host + ":" + port : host) : port; var operation = (_c = (_b = http === null || http === void 0 ? void 0 : http.path) !== null && _b !== void 0 ? _b : event.rawPath) !== null && _c !== void 0 ? _c : (context.functionName ? "/" + context.functionName : '/'); var query = event.rawQueryString ? "?" + event.rawQueryString : event.queryStringParameters ? '?' + Object.entries(event.queryStringParameters) .map(function (_a) { var k = _a[0], v = _a[1]; return k + "=" + v; }) .join('&') : ''; var carrier = headers && ContextCarrier_1.ContextCarrier.from(headers); var span = method && AgentConfig_1.ignoreHttpMethodCheck(method) ? DummySpan_1.default.create() : ContextManager_1.default.current.newEntrySpan(operation, carrier); span.layer = Tracing_pb_1.SpanLayer.HTTP; span.component = Component_1.Component.AWSLAMBDA_GATEWAYAPIHTTP; span.peer = (_e = (_d = http === null || http === void 0 ? void 0 : http.sourceIp) !== null && _d !== void 0 ? _d : headers === null || headers === void 0 ? void 0 : headers['x-forwarded-for']) !== null && _e !== void 0 ? _e : 'Unknown'; if (method) span.tag(Tag_1.default.httpMethod(method)); if (hostport && proto) span.tag(Tag_1.default.httpURL(new url_1.URL(proto + "://" + hostport + operation + query).toString())); span.start(); return span; }; AWSLambdaGatewayAPIHTTP.prototype.stop = function (span, err, res) { var statusCode = (res === null || res === void 0 ? void 0 : res.statusCode) || (typeof res === 'number' ? res : err ? 500 : null); if (statusCode) { if (statusCode >= 400) span.errored = true; span.tag(Tag_1.default.httpStatusCode(statusCode)); } span.stop(); }; return AWSLambdaGatewayAPIHTTP; }(AWSLambdaTriggerPlugin_1.AWSLambdaTriggerPlugin)); exports.default = new AWSLambdaGatewayAPIHTTP(); //# sourceMappingURL=AWSLambdaGatewayAPIHTTP.js.map