Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics.Tracing;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Instrumentation.AWS;

[EventSource(Name = "OpenTelemetry-Instrumentation-AWS")]
internal sealed class AWSInstrumentationEventSource : EventSource
{
public static AWSInstrumentationEventSource Log = new();

private const int EventIdFailedToParseJson = 1;

[NonEvent]
public void JsonParserException(string format, Exception ex)
{
if (this.IsEnabled(EventLevel.Error, EventKeywords.All))
{
this.FailedToPraseJson(format, ex.ToInvariantString());
}
}

[Event(EventIdFailedToParseJson, Message = "Failed to parse Json in {0}. Error Message: '{1}'", Level = EventLevel.Warning)]
public void FailedToPraseJson(string format, string exception)
{
this.WriteEvent(EventIdFailedToParseJson, format, exception);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,90 +20,47 @@ public AWSServiceHelper(AWSSemanticConventions semanticConventions)
.AddAttributeAWSBedrockDataSourceId("DataSourceId")
.AddAttributeAWSBedrockGuardrailId("GuardrailId")
.AddAttributeAWSBedrockKnowledgeBaseId("KnowledgeBaseId")
.AddAttributeAWSSQSQueueName("QueueName")
.AddAttributeAwsS3Bucket("BucketName")
.AddAttributeAwsKinesisStreamName("StreamName")
.AddAttributeAwsSnsTopicArn("TopicArn")
.AddAttributeAwsSecretsmanagerSecretArn("ARN")
.AddAttributeAwsSecretsmanagerSecretArn("SecretId")
.AddAttributeAwsStepFunctionsActivityArn("ActivityArn")
.AddAttributeAwsStepFunctionsStateMachineArn("StateMachineArn")
.AddAttributeAwsLambdaResourceMappingId("UUID")
.AddAttributeAWSLambdaFunctionName("FunctionName")
.AddAttributeAWSKinesisStreamArn("StreamArn")
.AddAttributeAWSDynamoTableArn("TableArn")
.AddAttributeAWSBedrockGuardrailArn("GuardrailArn")
.Build();
}

internal static IReadOnlyDictionary<string, List<string>> ServiceRequestParameterMap { get; } = new Dictionary<string, List<string>>()
{
{ AWSServiceType.DynamoDbService, ["TableName"] },
{ AWSServiceType.SQSService, ["QueueUrl"] },
{ AWSServiceType.DynamoDbService, ["TableName", "TableArn"] },
{ AWSServiceType.SQSService, ["QueueUrl", "QueueName"] },
{ AWSServiceType.BedrockAgentService, ["AgentId", "KnowledgeBaseId", "DataSourceId"] },
{ AWSServiceType.BedrockAgentRuntimeService, ["AgentId", "KnowledgeBaseId"] },
{ AWSServiceType.BedrockRuntimeService, ["ModelId"] },
{ AWSServiceType.S3Service, ["BucketName"] },
{ AWSServiceType.KinesisService, ["StreamName", "StreamArn"] },
{ AWSServiceType.LambdaService, ["UUID", "FunctionName"] },
{ AWSServiceType.SecretsManagerService, ["SecretId"] },
{ AWSServiceType.SNSService, ["TopicArn"] },
{ AWSServiceType.StepFunctionsService, ["ActivityArn", "StateMachineArn"] },
};

internal static IReadOnlyDictionary<string, List<string>> ServiceResponseParameterMap { get; } = new Dictionary<string, List<string>>()
{
{ AWSServiceType.BedrockService, ["GuardrailId"] },
{ AWSServiceType.BedrockService, ["GuardrailId", "GuardrailArn"] },
{ AWSServiceType.BedrockAgentService, ["AgentId", "DataSourceId"] },
{ AWSServiceType.SecretsManagerService, ["ARN"] },
{ AWSServiceType.SQSService, ["QueueUrl"] },
};

// for Bedrock Agent operations, we map each supported operation to one resource: Agent, DataSource, or KnowledgeBase
internal static List<string> BedrockAgentAgentOps { get; } =
[
"CreateAgentActionGroup",
"CreateAgentAlias",
"DeleteAgentActionGroup",
"DeleteAgentAlias",
"DeleteAgent",
"DeleteAgentVersion",
"GetAgentActionGroup",
"GetAgentAlias",
"GetAgent",
"GetAgentVersion",
"ListAgentActionGroups",
"ListAgentAliases",
"ListAgentKnowledgeBases",
"ListAgentVersions",
"PrepareAgent",
"UpdateAgentActionGroup",
"UpdateAgentAlias",
"UpdateAgent"
];

internal static List<string> BedrockAgentKnowledgeBaseOps { get; } =
[
"AssociateAgentKnowledgeBase",
"CreateDataSource",
"DeleteKnowledgeBase",
"DisassociateAgentKnowledgeBase",
"GetAgentKnowledgeBase",
"GetKnowledgeBase",
"ListDataSources",
"UpdateAgentKnowledgeBase"
];

internal static List<string> BedrockAgentDataSourceOps { get; } =
[
"DeleteDataSource",
"GetDataSource",
"UpdateDataSource"
];

internal IDictionary<string, string> ParameterAttributeMap { get; }

internal static IReadOnlyDictionary<string, string> OperationNameToResourceMap()
{
var operationClassMap = new Dictionary<string, string>();

foreach (var op in BedrockAgentKnowledgeBaseOps)
{
operationClassMap[op] = "KnowledgeBaseId";
}

foreach (var op in BedrockAgentDataSourceOps)
{
operationClassMap[op] = "DataSourceId";
}

foreach (var op in BedrockAgentAgentOps)
{
operationClassMap[op] = "AgentId";
}

return operationClassMap;
}

internal static string GetAWSServiceName(IRequestContext requestContext)
=> Utils.RemoveAmazonPrefixFromServiceName(requestContext.ServiceMetaData.ServiceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ internal class AWSServiceType
internal const string BedrockAgentService = "Bedrock Agent";
internal const string BedrockAgentRuntimeService = "Bedrock Agent Runtime";
internal const string BedrockRuntimeService = "Bedrock Runtime";
internal const string S3Service = "S3";
internal const string KinesisService = "Kinesis";
internal const string LambdaService = "Lambda";
internal const string SecretsManagerService = "Secrets Manager";
internal const string StepFunctionsService = "SFN";

internal static bool IsDynamoDbService(string service)
=> DynamoDbService.Equals(service, StringComparison.OrdinalIgnoreCase);
Expand All @@ -33,4 +38,19 @@ internal static bool IsBedrockAgentRuntimeService(string service)

internal static bool IsBedrockRuntimeService(string service)
=> BedrockRuntimeService.Equals(service, StringComparison.OrdinalIgnoreCase);

internal static bool IsS3Service(string service)
=> S3Service.Equals(service, StringComparison.OrdinalIgnoreCase);

internal static bool IsKinesisService(string service)
=> KinesisService.Equals(service, StringComparison.OrdinalIgnoreCase);

internal static bool IsLambdaService(string service)
=> LambdaService.Equals(service, StringComparison.OrdinalIgnoreCase);

internal static bool IsSecretsManagerService(string service)
=> SecretsManagerService.Equals(service, StringComparison.OrdinalIgnoreCase);

internal static bool IsStepFunctionsService(string service)
=> StepFunctionsService.Equals(service, StringComparison.OrdinalIgnoreCase);
}
Loading