-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental AWS Lambda Function support (#70)
- Loading branch information
Showing
13 changed files
with
419 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,8 @@ module.exports = { | |
}, | ||
env: { | ||
node: true | ||
}, | ||
globals: { | ||
"NodeJS": true | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,6 @@ export default interface Protocol { | |
heartbeat(): this; | ||
|
||
report(): this; | ||
|
||
flush(): Promise<any> | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ export default interface Client { | |
readonly isConnected: boolean; | ||
|
||
start(): void; | ||
|
||
flush(): Promise<any> | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*! | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
import { URL } from 'url'; | ||
import ContextManager from '../trace/context/ContextManager'; | ||
import { Component } from '../trace/Component'; | ||
import Tag from '../Tag'; | ||
import { SpanLayer } from '../proto/language-agent/Tracing_pb'; | ||
import { ContextCarrier } from '../trace/context/ContextCarrier'; | ||
import Span from '../trace/span/Span'; | ||
import DummySpan from '../trace/span/DummySpan'; | ||
import { ignoreHttpMethodCheck } from '../config/AgentConfig'; | ||
import { AWSLambdaTriggerPlugin } from './AWSLambdaTriggerPlugin'; | ||
|
||
class AWSLambdaGatewayAPIHTTP extends AWSLambdaTriggerPlugin { | ||
start(event: any, context: any): Span { | ||
const headers = event.headers; | ||
const reqCtx = event.requestContext; | ||
const http = reqCtx?.http; | ||
const method = http?.method; | ||
const proto = http?.protocol ? http.protocol.split('/')[0].toLowerCase() : headers?.['x-forwarded-proto']; | ||
const port = headers?.['x-forwarded-port'] || ''; | ||
const host = headers?.host ?? (reqCtx?.domainName || ''); | ||
const hostport = host ? (port ? `${host}:${port}` : host) : port; | ||
const operation = http?.path ?? event.rawPath ?? (context.functionName ? `/${context.functionName}` : '/'); | ||
|
||
const query = event.rawQueryString | ||
? `?${event.rawQueryString}` | ||
: event.queryStringParameters | ||
? '?' + | ||
Object.entries(event.queryStringParameters) | ||
.map(([k, v]) => `${k}=${v}`) | ||
.join('&') | ||
: ''; | ||
|
||
const carrier = headers && ContextCarrier.from(headers); | ||
|
||
const span = | ||
method && ignoreHttpMethodCheck(method) | ||
? DummySpan.create() | ||
: ContextManager.current.newEntrySpan(operation, carrier); | ||
|
||
span.layer = SpanLayer.HTTP; | ||
span.component = Component.AWSLAMBDA_GATEWAYAPIHTTP; | ||
span.peer = http?.sourceIp ?? headers?.['x-forwarded-for'] ?? 'Unknown'; | ||
|
||
if (method) span.tag(Tag.httpMethod(method)); | ||
|
||
if (hostport && proto) span.tag(Tag.httpURL(new URL(`${proto}://${hostport}${operation}${query}`).toString())); | ||
|
||
span.start(); | ||
|
||
return span; | ||
} | ||
|
||
stop(span: Span, err: Error | null, res: any): void { | ||
const statusCode = res?.statusCode || (typeof res === 'number' ? res : err ? 500 : null); | ||
|
||
if (statusCode) { | ||
if (statusCode >= 400) span.errored = true; | ||
|
||
span.tag(Tag.httpStatusCode(statusCode)); | ||
} | ||
|
||
span.stop(); | ||
} | ||
} | ||
|
||
export default new AWSLambdaGatewayAPIHTTP(); |
Oops, something went wrong.