-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from awslabs/dev
Release 0.1.0
- Loading branch information
Showing
35 changed files
with
699 additions
and
183 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Semgrep | ||
|
||
on: | ||
# Scan changed files in PRs, block on new issues only (existing issues ignored) | ||
pull_request: | ||
|
||
push: | ||
branches: ["dev", "main"] | ||
|
||
schedule: | ||
- cron: '23 20 * * 1' | ||
|
||
# Manually trigger the workflow | ||
workflow_dispatch: | ||
|
||
jobs: | ||
semgrep: | ||
name: Scan | ||
permissions: | ||
security-events: write | ||
runs-on: ubuntu-latest | ||
container: | ||
image: returntocorp/semgrep | ||
# Skip any PR created by dependabot to avoid permission issues | ||
if: (github.actor != 'dependabot[bot]') | ||
steps: | ||
# Fetch project source | ||
- uses: actions/checkout@v4 | ||
|
||
- run: semgrep ci --sarif > semgrep.sarif | ||
env: | ||
SEMGREP_RULES: >- # more at semgrep.dev/explore | ||
p/security-audit | ||
p/secrets | ||
p/owasp-top-ten | ||
- name: Upload SARIF file for GitHub Advanced Security Dashboard | ||
uses: github/codeql-action/upload-sarif@v2 | ||
with: | ||
sarif_file: semgrep.sarif | ||
if: always() |
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,2 @@ | ||
/sampleapps | ||
/test |
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 @@ | ||
# Changelog |
Binary file not shown.
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
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
38 changes: 38 additions & 0 deletions
38
src/AWS.Messaging.Telemetry.OpenTelemetry/AWS.Messaging.Telemetry.OpenTelemetry.csproj
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,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>true</IsPackable> | ||
<Product>AWS Message Processing Framework Instrumention for OpenTelemetry</Product> | ||
<PackageProjectUrl>https://github.com/awslabs/aws-dotnet-messaging</PackageProjectUrl> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<RollForward>Major</RollForward> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<WarningsAsErrors>CA1727</WarningsAsErrors> | ||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>..\..\public.snk</AssemblyOriginatorKeyFile> | ||
<Version>0.1.0</Version> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="OpenTelemetry" Version="1.6.0" /> | ||
<PackageReference Include="OpenTelemetry.Api" Version="1.6.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\AWS.Messaging\AWS.Messaging.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\LICENSE" Pack="true" PackagePath="" /> | ||
<None Include="..\..\NOTICE" Pack="true" PackagePath="" /> | ||
<None Include="..\..\THIRD_PARTY_LICENSES" Pack="true" PackagePath="" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include=".\README.md" Pack="true" PackagePath="" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,15 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace AWS.Messaging.Telemetry.OpenTelemetry; | ||
|
||
/// <summary> | ||
/// Constants related to the OpenTelemetry instrumentation for AWS.Messaging | ||
/// </summary> | ||
public class Constants | ||
{ | ||
/// <summary> | ||
/// OpenTelemetry activity source name | ||
/// </summary> | ||
public const string SourceName = "AWS.Messaging"; | ||
} |
83 changes: 83 additions & 0 deletions
83
src/AWS.Messaging.Telemetry.OpenTelemetry/OpenTelemetryProvider.cs
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,83 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Diagnostics; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Context.Propagation; | ||
|
||
namespace AWS.Messaging.Telemetry.OpenTelemetry; | ||
|
||
/// <summary> | ||
/// Creates OpenTelemetry traces | ||
/// </summary> | ||
public class OpenTelemetryProvider : ITelemetryProvider | ||
{ | ||
private static readonly ActivitySource _activitySource = new ActivitySource(Constants.SourceName, TelemetryKeys.AWSMessagingAssemblyVersion); | ||
|
||
/// <inheritdoc/> | ||
public ITelemetryTrace Trace(string traceName) | ||
{ | ||
var activity = _activitySource.StartActivity(traceName, ActivityKind.Producer); | ||
if (activity != null) | ||
{ | ||
return new OpenTelemetryTrace(activity); | ||
} | ||
|
||
// If we initially failed to create an activity, attempt to force creation with | ||
// a link to the current activity, see https://opentelemetry.io/docs/instrumentation/net/manual/#creating-new-root-activities | ||
var parentActivity = Activity.Current; | ||
Activity.Current = null; | ||
ActivityLink[]? links = null; | ||
if (parentActivity != null) | ||
{ | ||
links = new[] { new ActivityLink(parentActivity.Context) }; | ||
} | ||
|
||
activity = _activitySource.StartActivity(traceName, ActivityKind.Producer, parentContext: default, links: links); | ||
|
||
return new OpenTelemetryTrace(activity, parentActivity); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public ITelemetryTrace Trace(string traceName, MessageEnvelope envelope) | ||
{ | ||
var propogatedContext = Propagators.DefaultTextMapPropagator.Extract(default, envelope, ExtractTraceContextFromEnvelope); | ||
Baggage.Current = propogatedContext.Baggage; | ||
|
||
var activity = _activitySource.StartActivity(traceName, ActivityKind.Consumer, parentContext: propogatedContext.ActivityContext); | ||
if (activity != null) | ||
{ | ||
return new OpenTelemetryTrace(activity); | ||
} | ||
|
||
// If we initially failed to create an activity, attempt to force creation with | ||
// a link to the current activity, see https://opentelemetry.io/docs/instrumentation/net/manual/#creating-new-root-activities | ||
var parentActivity = Activity.Current; | ||
Activity.Current = null; | ||
ActivityLink[]? links = null; | ||
if (parentActivity != null) | ||
{ | ||
links = new[] { new ActivityLink(parentActivity.Context) }; | ||
} | ||
|
||
activity = _activitySource.StartActivity(traceName, ActivityKind.Consumer, parentContext: propogatedContext.ActivityContext, links: links); | ||
|
||
return new OpenTelemetryTrace(activity, parentActivity); | ||
} | ||
|
||
/// <summary> | ||
/// Extracts propagation context from a <see cref="MessageEnvelope"/>, meant to be used with <see cref="TextMapPropagator"/> | ||
/// </summary> | ||
/// <param name="envelope">Inbound message envelope</param> | ||
/// <param name="key">Context key</param> | ||
/// <returns>Context value</returns> | ||
private IEnumerable<string> ExtractTraceContextFromEnvelope(MessageEnvelope envelope, string key) | ||
{ | ||
if (envelope.Metadata.TryGetValue(key, out var jsonElement)) | ||
{ | ||
return new string[] { jsonElement.ToString() }; | ||
} | ||
|
||
return Enumerable.Empty<string>(); | ||
} | ||
} |
Oops, something went wrong.