Skip to content

Commit

Permalink
Merge branch 'main' into OTEL_METRIC_EXPORT-env-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Jul 15, 2022
2 parents 03ccd1b + bc4f788 commit 0a0d734
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* `LogRecord` instances are now reused to reduce memory pressure
([#3385](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3385))

* Fix exact match of activity source name when `wildcard` is used.
([#3446](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3446))

## 1.3.0

Released 2022-Jun-03
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Internal/WildcardHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public static Regex GetWildcardRegex(IEnumerable<string> patterns = default)
var convertedPattern = string.Join(
"|",
from p in patterns select "(?:" + Regex.Escape(p).Replace("\\*", ".*").Replace("\\?", ".") + ')');
return new Regex('^' + convertedPattern + '$', RegexOptions.Compiled | RegexOptions.IgnoreCase);
return new Regex("^(?:" + convertedPattern + ")$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
}
}
41 changes: 41 additions & 0 deletions test/OpenTelemetry.Tests/Internal/WildcardHelperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// <copyright file="WildcardHelperTests.cs" company="OpenTelemetry Authors">
// 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
//
// 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.
// </copyright>

using Xunit;

namespace OpenTelemetry.Internal.Tests
{
public class WildcardHelperTests
{
[Theory]
[InlineData(new[] { "a" }, "a", true)]
[InlineData(new[] { "a.*" }, "a.b", true)]
[InlineData(new[] { "a" }, "a.b", false)]
[InlineData(new[] { "a", "x.*" }, "x.y", true)]
[InlineData(new[] { "a", "x.*" }, "a.b", false)]
[InlineData(new[] { "a", "x", "y" }, "abbbt", false)]
[InlineData(new[] { "a", "x", "y" }, "ccxccc", false)]
[InlineData(new[] { "a", "x", "y" }, "wecgy", false)]
public void WildcardRegex_ShouldMatch(string[] patterns, string matchWith, bool isMatch)
{
var regex = WildcardHelper.GetWildcardRegex(patterns);

var result = regex.IsMatch(matchWith);

Assert.True(result == isMatch);
}
}
}

0 comments on commit 0a0d734

Please sign in to comment.