Skip to content
v2.278.0

MetricFilterProps Struct ​

Properties for a MetricFilter.

Example ​

ts
const repository = new ecr.Repository(this, 'TestRepository');

const runtime = new agentcore.Runtime(this, 'Runtime', {
  agentRuntimeArtifact: agentcore.AgentRuntimeArtifact.fromEcrRepository(repository, 'v1.0.0'),
});

new logs.MetricFilter(this, 'ToolErrors', {
  logGroup: runtime.applicationLogGroup,
  filterPattern: logs.FilterPattern.stringValue('$.tool_status', '=', 'error'),
  metricNamespace: 'MyApp',
  metricName: 'ToolExecutionErrors',
});
python
repository = ecr.Repository(self, "TestRepository")

runtime = agentcore.Runtime(self, "Runtime",
    agent_runtime_artifact=agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
)

logs.MetricFilter(self, "ToolErrors",
    log_group=runtime.application_log_group,
    filter_pattern=logs.FilterPattern.string_value("$.tool_status", "=", "error"),
    metric_namespace="MyApp",
    metric_name="ToolExecutionErrors"
)
java
Repository repository = new Repository(this, "TestRepository");

Runtime runtime = Runtime.Builder.create(this, "Runtime")
        .agentRuntimeArtifact(AgentRuntimeArtifact.fromEcrRepository(repository, "v1.0.0"))
        .build();

MetricFilter.Builder.create(this, "ToolErrors")
        .logGroup(runtime.getApplicationLogGroup())
        .filterPattern(FilterPattern.stringValue("$.tool_status", "=", "error"))
        .metricNamespace("MyApp")
        .metricName("ToolExecutionErrors")
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var repository = new Repository(this, "TestRepository");

var runtime = new Runtime(this, "Runtime", new RuntimeProps {
    AgentRuntimeArtifact = AgentRuntimeArtifact.FromEcrRepository(repository, "v1.0.0")
});

new MetricFilter(this, "ToolErrors", new MetricFilterProps {
    LogGroup = runtime.ApplicationLogGroup,
    FilterPattern = FilterPattern.StringValue("$.tool_status", "=", "error"),
    MetricNamespace = "MyApp",
    MetricName = "ToolExecutionErrors"
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
repository := ecr.NewRepository(this, jsii.String("TestRepository"))

runtime := agentcore.NewRuntime(this, jsii.String("Runtime"), &RuntimeProps{
	AgentRuntimeArtifact: agentcore.AgentRuntimeArtifact_FromEcrRepository(repository, jsii.String("v1.0.0")),
})

logs.NewMetricFilter(this, jsii.String("ToolErrors"), &MetricFilterProps{
	LogGroup: runtime.applicationLogGroup,
	FilterPattern: logs.FilterPattern_StringValue(jsii.String("$.tool_status"), jsii.String("="), jsii.String("error")),
	MetricNamespace: jsii.String("MyApp"),
	MetricName: jsii.String("ToolExecutionErrors"),
})

Properties ​

applyOnTransformedLogsoptionalbooleanapply_on_transformed_logsoptionalboolapplyOnTransformedLogsoptionalBooleanApplyOnTransformedLogsoptionalboolApplyOnTransformedLogsoptional*bool = false #
Whether the metric filter is applied on the tranformed logs.

This parameter is valid only for log groups that have an active log transformer. If this value is true, the metric filter is applied on the transformed version of the log events instead of the original ingested log events.

defaultValueoptionalnumberdefault_valueoptionalint | floatdefaultValueoptionalNumberDefaultValueoptionaldoubleDefaultValueoptional*float64 #
The value to emit if the pattern does not match a particular event.

Default: No metric emitted.

dimensionsoptional{ [key: string]: string }dimensionsoptionaltyping.Mapping[str, str]dimensionsoptionalMap<String, String>DimensionsoptionalIDictionary<string, string>Dimensionsoptional*map[string]*string #
The fields to use as dimensions for the metric.

Default: No dimensions attached to metrics.

One metric filter can include as many as three dimensions.

filterNameoptionalstringfilter_nameoptionalstrfilterNameoptionalStringFilterNameoptionalstringFilterNameoptional*string #
The name of the metric filter.

Default: Cloudformation generated name.

filterPatternIFilterPatternfilter_patternIFilterPatternfilterPatternIFilterPatternFilterPatternIFilterPatternFilterPatternIFilterPattern required #
Pattern to search for log events.
logGroupILogGroupReflog_groupILogGroupReflogGroupILogGroupRefLogGroupILogGroupRefLogGroupILogGroupRef required #
The log group to create the filter on.
metricNamestringmetric_namestrmetricNameStringMetricNamestringMetricName*string required #
The name of the metric to emit.
metricNamespacestringmetric_namespacestrmetricNamespaceStringMetricNamespacestringMetricNamespace*string required #
The namespace of the metric to emit.
metricValueoptionalstringmetric_valueoptionalstrmetricValueoptionalStringMetricValueoptionalstringMetricValueoptional*string = "1" #
The value to emit for the metric.
notes

Can either be a literal number (typically "1"), or the name of a field in the structure to take the value from the matched event. If you are using a field value, the field value must have been matched using the pattern.

If you want to specify a field from a matched JSON structure, use '.fieldName′,andmakesurethefieldisinthepattern(ifonlyas′.fieldName = *').

If you want to specify a field from a matched space-delimited structure, use '$fieldName'.

unitoptionalUnitunitoptionalUnitunitoptionalUnitUnitoptionalUnitUnitoptionalUnit #
The unit to assign to the metric.

Default: No unit attached to metrics.