-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into instrumentation-iter-modules
- Loading branch information
Showing
16 changed files
with
422 additions
and
109 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
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,24 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
export enum TracesSamplerValues { | ||
AlwaysOff = 'always_off', | ||
AlwaysOn = 'always_on', | ||
ParentBasedAlwaysOff = 'parentbased_always_off', | ||
ParentBasedAlwaysOn = 'parentbased_always_on', | ||
ParentBasedTraceIdRatio = 'parentbased_traceidratio', | ||
TraceIdRatio = 'traceidratio', | ||
} |
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
58 changes: 58 additions & 0 deletions
58
packages/opentelemetry-resource-detector-aws/src/detectors/AwsLambdaDetector.ts
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,58 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 { | ||
Detector, | ||
Resource, | ||
CLOUD_RESOURCE, | ||
ResourceDetectionConfig, | ||
} from '@opentelemetry/resources'; | ||
|
||
/** | ||
* The AwsLambdaDetector can be used to detect if a process is running in AWS Lambda | ||
* and return a {@link Resource} populated with data about the environment. | ||
* Returns an empty Resource if detection fails. | ||
*/ | ||
export class AwsLambdaDetector implements Detector { | ||
async detect(_config?: ResourceDetectionConfig): Promise<Resource> { | ||
const functionName = process.env.AWS_LAMBDA_FUNCTION_NAME; | ||
if (!functionName) { | ||
return Resource.empty(); | ||
} | ||
|
||
const functionVersion = process.env.AWS_LAMBDA_FUNCTION_VERSION; | ||
const region = process.env.AWS_REGION; | ||
|
||
const attributes = { | ||
[CLOUD_RESOURCE.PROVIDER]: 'aws', | ||
}; | ||
if (region) { | ||
attributes[CLOUD_RESOURCE.REGION] = region; | ||
} | ||
|
||
// TODO(https://github.com/open-telemetry/opentelemetry-js/issues/2123): Migrate to FAAS_RESOURCE when defined. | ||
if (functionName) { | ||
attributes['faas.name'] = functionName; | ||
} | ||
if (functionVersion) { | ||
attributes['faas.version'] = functionVersion; | ||
} | ||
|
||
return new Resource(attributes); | ||
} | ||
} | ||
|
||
export const awsLambdaDetector = new AwsLambdaDetector(); |
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
64 changes: 64 additions & 0 deletions
64
packages/opentelemetry-resource-detector-aws/test/detectors/AwsLambdaDetector.test.ts
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,64 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 * as assert from 'assert'; | ||
import { | ||
assertCloudResource, | ||
assertEmptyResource, | ||
} from '@opentelemetry/resources/test/util/resource-assertions'; | ||
|
||
import { awsLambdaDetector } from '../../src'; | ||
|
||
describe('awsLambdaDetector', () => { | ||
let oldEnv: NodeJS.ProcessEnv; | ||
|
||
beforeEach(() => { | ||
oldEnv = { ...process.env }; | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = oldEnv; | ||
}); | ||
|
||
describe('on lambda', () => { | ||
it('fills resource', async () => { | ||
process.env.AWS_LAMBDA_FUNCTION_NAME = 'name'; | ||
process.env.AWS_LAMBDA_FUNCTION_VERSION = 'v1'; | ||
process.env.AWS_REGION = 'us-east-1'; | ||
|
||
const resource = await awsLambdaDetector.detect(); | ||
|
||
assertCloudResource(resource, { | ||
provider: 'aws', | ||
region: 'us-east-1', | ||
}); | ||
|
||
assert.strictEqual(resource.attributes['faas.name'], 'name'); | ||
assert.strictEqual(resource.attributes['faas.version'], 'v1'); | ||
}); | ||
}); | ||
|
||
describe('not on lambda', () => { | ||
it('returns empty resource', async () => { | ||
process.env.AWS_LAMBDA_FUNCTION_VERSION = 'v1'; | ||
process.env.AWS_REGION = 'us-east-1'; | ||
|
||
const resource = await awsLambdaDetector.detect(); | ||
|
||
assertEmptyResource(resource); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.