Organize StyleCop Settings and enable StyleCop on Tests (#715)
* Enable StyleCop rules for Test projects This enables most of the StyleCop for test projects cleaning up any errors as appropriate. * Enable StyleCop rules for Test projects This enables most of the StyleCop for test projects cleaning up any errors as appropriate. * Add line break at end of ruleset files * Correct multi-line parameter after rebase
This commit is contained in:
parent
c7333e49fe
commit
8ed37a6f59
|
|
@ -5,6 +5,7 @@
|
|||
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)/debug.snk</AssemblyOriginatorKeyFile>
|
||||
<DefineConstants>$(DefineConstants);SIGNED</DefineConstants>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<NoWarn>$(NoWarn),1574,1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
|
||||
|
|
|
|||
|
|
@ -5,168 +5,9 @@
|
|||
<Description Resource="OpenTelemetrySDKRules_Description" />
|
||||
</Localization>
|
||||
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
|
||||
<Rule Id="SA1000" Action="Error" />
|
||||
<Rule Id="SA1001" Action="Error" />
|
||||
<Rule Id="SA1002" Action="Error" />
|
||||
<Rule Id="SA1003" Action="Error" />
|
||||
<Rule Id="SA1004" Action="Error" />
|
||||
<Rule Id="SA1005" Action="Error" />
|
||||
<Rule Id="SA1006" Action="Error" />
|
||||
<Rule Id="SA1007" Action="Error" />
|
||||
<Rule Id="SA1008" Action="Error" />
|
||||
<Rule Id="SA1009" Action="Error" />
|
||||
<Rule Id="SA1010" Action="Error" />
|
||||
<Rule Id="SA1011" Action="Error" />
|
||||
<Rule Id="SA1012" Action="Error" />
|
||||
<Rule Id="SA1013" Action="Error" />
|
||||
<Rule Id="SA1014" Action="Error" />
|
||||
<Rule Id="SA1015" Action="Error" />
|
||||
<Rule Id="SA1016" Action="Error" />
|
||||
<Rule Id="SA1017" Action="Error" />
|
||||
<Rule Id="SA1018" Action="Error" />
|
||||
<Rule Id="SA1019" Action="Error" />
|
||||
<Rule Id="SA1020" Action="Error" />
|
||||
<Rule Id="SA1021" Action="Error" />
|
||||
<Rule Id="SA1022" Action="Error" />
|
||||
<Rule Id="SA1023" Action="Error" />
|
||||
<Rule Id="SA1024" Action="Error" />
|
||||
<Rule Id="SA1025" Action="Error" />
|
||||
<Rule Id="SA1026" Action="Error" />
|
||||
<Rule Id="SA1027" Action="Error" />
|
||||
<Rule Id="SA1028" Action="Error" />
|
||||
<Rule Id="SA1100" Action="Error" />
|
||||
<Rule Id="SA1101" Action="Error" />
|
||||
<Rule Id="SA1102" Action="Error" />
|
||||
<Rule Id="SA1103" Action="Error" />
|
||||
<Rule Id="SA1104" Action="Error" />
|
||||
<Rule Id="SA1105" Action="Error" />
|
||||
<Rule Id="SA1106" Action="Error" />
|
||||
<Rule Id="SA1107" Action="Error" />
|
||||
<Rule Id="SA1108" Action="Error" />
|
||||
<Rule Id="SA1110" Action="Error" />
|
||||
<Rule Id="SA1111" Action="Error" />
|
||||
<Rule Id="SA1112" Action="Error" />
|
||||
<Rule Id="SA1113" Action="Error" />
|
||||
<Rule Id="SA1114" Action="Error" />
|
||||
<Rule Id="SA1115" Action="Error" />
|
||||
<Rule Id="SA1116" Action="Error" />
|
||||
<Rule Id="SA1117" Action="Error" />
|
||||
<Rule Id="SA1118" Action="Error" />
|
||||
<Rule Id="SA1119" Action="Error" />
|
||||
<Rule Id="SA1120" Action="Error" />
|
||||
<Rule Id="SA1121" Action="Error" />
|
||||
<Rule Id="SA1122" Action="Error" />
|
||||
<Rule Id="SA1123" Action="Error" />
|
||||
<Rule Id="SA1124" Action="Error" />
|
||||
<Rule Id="SA1125" Action="Error" />
|
||||
<Rule Id="SA1127" Action="Error" />
|
||||
<Rule Id="SA1128" Action="Error" />
|
||||
<Rule Id="SA1129" Action="Error" />
|
||||
<Rule Id="SA1130" Action="Error" />
|
||||
<Rule Id="SA1131" Action="Error" />
|
||||
<Rule Id="SA1132" Action="Error" />
|
||||
<Rule Id="SA1133" Action="Error" />
|
||||
<Rule Id="SA1134" Action="Error" />
|
||||
<Rule Id="SA1200" Action="None" />
|
||||
<Rule Id="SA1201" Action="Error" />
|
||||
<Rule Id="SA1202" Action="Error" />
|
||||
<Rule Id="SA1203" Action="Error" />
|
||||
<Rule Id="SA1204" Action="Error" />
|
||||
<Rule Id="SA1205" Action="Error" />
|
||||
<Rule Id="SA1206" Action="Error" />
|
||||
<Rule Id="SA1207" Action="Error" />
|
||||
<Rule Id="SA1208" Action="Error" />
|
||||
<Rule Id="SA1209" Action="Error" />
|
||||
<Rule Id="SA1210" Action="Error" />
|
||||
<Rule Id="SA1211" Action="Error" />
|
||||
<Rule Id="SA1212" Action="Error" />
|
||||
<Rule Id="SA1213" Action="Error" />
|
||||
<Rule Id="SA1214" Action="Error" />
|
||||
<Rule Id="SA1216" Action="Error" />
|
||||
<Rule Id="SA1217" Action="Error" />
|
||||
<Rule Id="SA1300" Action="Error" />
|
||||
<Rule Id="SA1302" Action="Error" />
|
||||
<Rule Id="SA1303" Action="Error" />
|
||||
<Rule Id="SA1304" Action="Error" />
|
||||
<Rule Id="SA1306" Action="Error" />
|
||||
<Rule Id="SA1307" Action="Error" />
|
||||
<Rule Id="SA1308" Action="Error" />
|
||||
<Rule Id="SA1309" Action="Error" />
|
||||
<Rule Id="SA1310" Action="Error" />
|
||||
<Rule Id="SA1311" Action="Error" />
|
||||
<Rule Id="SA1312" Action="Error" />
|
||||
<Rule Id="SA1313" Action="Error" />
|
||||
<Rule Id="SA1400" Action="Error" />
|
||||
<Rule Id="SA1401" Action="None" />
|
||||
<Rule Id="SA1402" Action="Error" />
|
||||
<Rule Id="SA1403" Action="Error" />
|
||||
<Rule Id="SA1404" Action="Error" />
|
||||
<Rule Id="SA1405" Action="Error" />
|
||||
<Rule Id="SA1406" Action="Error" />
|
||||
<Rule Id="SA1407" Action="Error" />
|
||||
<Rule Id="SA1408" Action="Error" />
|
||||
<Rule Id="SA1410" Action="Error" />
|
||||
<Rule Id="SA1411" Action="Error" />
|
||||
<Rule Id="SA1500" Action="Error" />
|
||||
<Rule Id="SA1501" Action="Error" />
|
||||
<Rule Id="SA1502" Action="Error" />
|
||||
<Rule Id="SA1503" Action="Error" />
|
||||
<Rule Id="SA1504" Action="Error" />
|
||||
<Rule Id="SA1505" Action="Error" />
|
||||
<Rule Id="SA1506" Action="Error" />
|
||||
<Rule Id="SA1507" Action="Error" />
|
||||
<Rule Id="SA1508" Action="Error" />
|
||||
<Rule Id="SA1509" Action="Error" />
|
||||
<Rule Id="SA1510" Action="Error" />
|
||||
<Rule Id="SA1511" Action="Error" />
|
||||
<Rule Id="SA1512" Action="None" />
|
||||
<Rule Id="SA1513" Action="Error" />
|
||||
<Rule Id="SA1514" Action="Error" />
|
||||
<Rule Id="SA1515" Action="Error" />
|
||||
<Rule Id="SA1516" Action="Error" />
|
||||
<Rule Id="SA1517" Action="Error" />
|
||||
<Rule Id="SA1518" Action="Error" />
|
||||
<Rule Id="SA1519" Action="Error" />
|
||||
<Rule Id="SA1520" Action="Error" />
|
||||
<Rule Id="SA1600" Action="None" />
|
||||
<Rule Id="SA1601" Action="Error" />
|
||||
<Rule Id="SA1602" Action="Error" />
|
||||
<Rule Id="SA1604" Action="Error" />
|
||||
<Rule Id="SA1605" Action="Error" />
|
||||
<Rule Id="SA1606" Action="Error" />
|
||||
<Rule Id="SA1607" Action="Error" />
|
||||
<Rule Id="SA1608" Action="Error" />
|
||||
<Rule Id="SA1610" Action="Error" />
|
||||
<Rule Id="SA1611" Action="Error" />
|
||||
<Rule Id="SA1612" Action="Error" />
|
||||
<Rule Id="SA1613" Action="Error" />
|
||||
<Rule Id="SA1614" Action="Error" />
|
||||
<Rule Id="SA1615" Action="Error" />
|
||||
<Rule Id="SA1616" Action="Error" />
|
||||
<Rule Id="SA1617" Action="Error" />
|
||||
<Rule Id="SA1618" Action="Error" />
|
||||
<Rule Id="SA1619" Action="Error" />
|
||||
<Rule Id="SA1620" Action="Error" />
|
||||
<Rule Id="SA1621" Action="Error" />
|
||||
<Rule Id="SA1622" Action="Error" />
|
||||
<Rule Id="SA1623" Action="Error" />
|
||||
<Rule Id="SA1624" Action="Error" />
|
||||
<Rule Id="SA1625" Action="Error" />
|
||||
<Rule Id="SA1626" Action="Error" />
|
||||
<Rule Id="SA1627" Action="Error" />
|
||||
<Rule Id="SA1633" Action="Error" />
|
||||
<Rule Id="SA1634" Action="Error" />
|
||||
<Rule Id="SA1635" Action="Error" />
|
||||
<Rule Id="SA1636" Action="Error" />
|
||||
<Rule Id="SA1637" Action="Error" />
|
||||
<Rule Id="SA1638" Action="Error" />
|
||||
<Rule Id="SA1640" Action="Error" />
|
||||
<Rule Id="SA1641" Action="Error" />
|
||||
<Rule Id="SA1642" Action="Error" />
|
||||
<Rule Id="SA1643" Action="Error" />
|
||||
<Rule Id="SA1648" Action="Error" />
|
||||
<Rule Id="SA1649" Action="Error" />
|
||||
<Rule Id="SA1651" Action="Error" />
|
||||
<Rule Id="SA1652" Action="Warning" />
|
||||
</Rules>
|
||||
</RuleSet>
|
||||
|
|
@ -6,168 +6,12 @@
|
|||
</Localization>
|
||||
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
|
||||
<Rule Id="SA0001" Action="None" />
|
||||
<Rule Id="SA1000" Action="None" />
|
||||
<Rule Id="SA1001" Action="None" />
|
||||
<Rule Id="SA1002" Action="None" />
|
||||
<Rule Id="SA1003" Action="None" />
|
||||
<Rule Id="SA1004" Action="None" />
|
||||
<Rule Id="SA1005" Action="None" />
|
||||
<Rule Id="SA1006" Action="None" />
|
||||
<Rule Id="SA1007" Action="None" />
|
||||
<Rule Id="SA1008" Action="None" />
|
||||
<Rule Id="SA1009" Action="None" />
|
||||
<Rule Id="SA1010" Action="None" />
|
||||
<Rule Id="SA1011" Action="None" />
|
||||
<Rule Id="SA1012" Action="None" />
|
||||
<Rule Id="SA1013" Action="None" />
|
||||
<Rule Id="SA1014" Action="None" />
|
||||
<Rule Id="SA1015" Action="None" />
|
||||
<Rule Id="SA1016" Action="None" />
|
||||
<Rule Id="SA1017" Action="None" />
|
||||
<Rule Id="SA1018" Action="None" />
|
||||
<Rule Id="SA1019" Action="None" />
|
||||
<Rule Id="SA1020" Action="None" />
|
||||
<Rule Id="SA1021" Action="None" />
|
||||
<Rule Id="SA1022" Action="None" />
|
||||
<Rule Id="SA1023" Action="None" />
|
||||
<Rule Id="SA1024" Action="None" />
|
||||
<Rule Id="SA1025" Action="None" />
|
||||
<Rule Id="SA1026" Action="None" />
|
||||
<Rule Id="SA1027" Action="None" />
|
||||
<Rule Id="SA1028" Action="None" />
|
||||
<Rule Id="SA1100" Action="None" />
|
||||
<Rule Id="SA1101" Action="None" />
|
||||
<Rule Id="SA1102" Action="None" />
|
||||
<Rule Id="SA1103" Action="None" />
|
||||
<Rule Id="SA1104" Action="None" />
|
||||
<Rule Id="SA1105" Action="None" />
|
||||
<Rule Id="SA1106" Action="None" />
|
||||
<Rule Id="SA1107" Action="None" />
|
||||
<Rule Id="SA1108" Action="None" />
|
||||
<Rule Id="SA1110" Action="None" />
|
||||
<Rule Id="SA1111" Action="None" />
|
||||
<Rule Id="SA1112" Action="None" />
|
||||
<Rule Id="SA1113" Action="None" />
|
||||
<Rule Id="SA1114" Action="None" />
|
||||
<Rule Id="SA1115" Action="None" />
|
||||
<Rule Id="SA1116" Action="None" />
|
||||
<Rule Id="SA1117" Action="None" />
|
||||
<Rule Id="SA1118" Action="None" />
|
||||
<Rule Id="SA1119" Action="None" />
|
||||
<Rule Id="SA1120" Action="None" />
|
||||
<Rule Id="SA1121" Action="None" />
|
||||
<Rule Id="SA1122" Action="None" />
|
||||
<Rule Id="SA1123" Action="None" />
|
||||
<Rule Id="SA1124" Action="None" />
|
||||
<Rule Id="SA1125" Action="None" />
|
||||
<Rule Id="SA1127" Action="None" />
|
||||
<Rule Id="SA1128" Action="None" />
|
||||
<Rule Id="SA1129" Action="None" />
|
||||
<Rule Id="SA1130" Action="None" />
|
||||
<Rule Id="SA1131" Action="None" />
|
||||
<Rule Id="SA1132" Action="None" />
|
||||
<Rule Id="SA1133" Action="None" />
|
||||
<Rule Id="SA1134" Action="None" />
|
||||
<Rule Id="SA1200" Action="None" />
|
||||
<Rule Id="SA1201" Action="None" />
|
||||
<Rule Id="SA1202" Action="None" />
|
||||
<Rule Id="SA1203" Action="None" />
|
||||
<Rule Id="SA1204" Action="None" />
|
||||
<Rule Id="SA1205" Action="None" />
|
||||
<Rule Id="SA1206" Action="None" />
|
||||
<Rule Id="SA1207" Action="None" />
|
||||
<Rule Id="SA1208" Action="None" />
|
||||
<Rule Id="SA1209" Action="None" />
|
||||
<Rule Id="SA1210" Action="None" />
|
||||
<Rule Id="SA1211" Action="None" />
|
||||
<Rule Id="SA1212" Action="None" />
|
||||
<Rule Id="SA1213" Action="None" />
|
||||
<Rule Id="SA1214" Action="None" />
|
||||
<Rule Id="SA1216" Action="None" />
|
||||
<Rule Id="SA1217" Action="None" />
|
||||
<Rule Id="SA1300" Action="None" />
|
||||
<Rule Id="SA1302" Action="None" />
|
||||
<Rule Id="SA1303" Action="None" />
|
||||
<Rule Id="SA1304" Action="None" />
|
||||
<Rule Id="SA1306" Action="None" />
|
||||
<Rule Id="SA1307" Action="None" />
|
||||
<Rule Id="SA1308" Action="None" />
|
||||
<Rule Id="SA1309" Action="None" />
|
||||
<Rule Id="SA1310" Action="None" />
|
||||
<Rule Id="SA1311" Action="None" />
|
||||
<Rule Id="SA1312" Action="None" />
|
||||
<Rule Id="SA1313" Action="None" />
|
||||
<Rule Id="SA1400" Action="None" />
|
||||
<Rule Id="SA1401" Action="None" />
|
||||
<Rule Id="SA1402" Action="None" />
|
||||
<Rule Id="SA1403" Action="None" />
|
||||
<Rule Id="SA1404" Action="None" />
|
||||
<Rule Id="SA1405" Action="None" />
|
||||
<Rule Id="SA1406" Action="None" />
|
||||
<Rule Id="SA1407" Action="None" />
|
||||
<Rule Id="SA1408" Action="None" />
|
||||
<Rule Id="SA1410" Action="None" />
|
||||
<Rule Id="SA1411" Action="None" />
|
||||
<Rule Id="SA1500" Action="None" />
|
||||
<Rule Id="SA1501" Action="None" />
|
||||
<Rule Id="SA1502" Action="None" />
|
||||
<Rule Id="SA1503" Action="None" />
|
||||
<Rule Id="SA1504" Action="None" />
|
||||
<Rule Id="SA1505" Action="None" />
|
||||
<Rule Id="SA1506" Action="None" />
|
||||
<Rule Id="SA1507" Action="None" />
|
||||
<Rule Id="SA1508" Action="None" />
|
||||
<Rule Id="SA1509" Action="None" />
|
||||
<Rule Id="SA1510" Action="None" />
|
||||
<Rule Id="SA1511" Action="None" />
|
||||
<Rule Id="SA1512" Action="None" />
|
||||
<Rule Id="SA1513" Action="None" />
|
||||
<Rule Id="SA1514" Action="None" />
|
||||
<Rule Id="SA1515" Action="None" />
|
||||
<Rule Id="SA1516" Action="None" />
|
||||
<Rule Id="SA1517" Action="None" />
|
||||
<Rule Id="SA1518" Action="None" />
|
||||
<Rule Id="SA1519" Action="None" />
|
||||
<Rule Id="SA1520" Action="None" />
|
||||
<Rule Id="SA1600" Action="None" />
|
||||
<Rule Id="SA1601" Action="None" />
|
||||
<Rule Id="SA1602" Action="None" />
|
||||
<Rule Id="SA1604" Action="None" />
|
||||
<Rule Id="SA1605" Action="None" />
|
||||
<Rule Id="SA1606" Action="None" />
|
||||
<Rule Id="SA1607" Action="None" />
|
||||
<Rule Id="SA1608" Action="None" />
|
||||
<Rule Id="SA1610" Action="None" />
|
||||
<Rule Id="SA1611" Action="None" />
|
||||
<Rule Id="SA1612" Action="None" />
|
||||
<Rule Id="SA1613" Action="None" />
|
||||
<Rule Id="SA1614" Action="None" />
|
||||
<Rule Id="SA1615" Action="None" />
|
||||
<Rule Id="SA1616" Action="None" />
|
||||
<Rule Id="SA1617" Action="None" />
|
||||
<Rule Id="SA1618" Action="None" />
|
||||
<Rule Id="SA1619" Action="None" />
|
||||
<Rule Id="SA1620" Action="None" />
|
||||
<Rule Id="SA1621" Action="None" />
|
||||
<Rule Id="SA1622" Action="None" />
|
||||
<Rule Id="SA1623" Action="None" />
|
||||
<Rule Id="SA1624" Action="None" />
|
||||
<Rule Id="SA1625" Action="None" />
|
||||
<Rule Id="SA1626" Action="None" />
|
||||
<Rule Id="SA1627" Action="None" />
|
||||
<Rule Id="SA1633" Action="Error" />
|
||||
<Rule Id="SA1634" Action="None" />
|
||||
<Rule Id="SA1635" Action="None" />
|
||||
<Rule Id="SA1636" Action="None" />
|
||||
<Rule Id="SA1637" Action="None" />
|
||||
<Rule Id="SA1638" Action="None" />
|
||||
<Rule Id="SA1640" Action="None" />
|
||||
<Rule Id="SA1641" Action="None" />
|
||||
<Rule Id="SA1642" Action="None" />
|
||||
<Rule Id="SA1643" Action="None" />
|
||||
<Rule Id="SA1648" Action="None" />
|
||||
<Rule Id="SA1649" Action="None" />
|
||||
<Rule Id="SA1651" Action="None" />
|
||||
<Rule Id="SA1652" Action="None" />
|
||||
</Rules>
|
||||
</RuleSet>
|
||||
|
|
@ -4,6 +4,9 @@
|
|||
"documentationRules": {
|
||||
"companyName": "OpenTelemetry Authors",
|
||||
"copyrightText": "Copyright The OpenTelemetry Authors\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License."
|
||||
},
|
||||
"orderingRules": {
|
||||
"usingDirectivesPlacement": "outsideNamespace"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ namespace Samples
|
|||
// All meters from this factory will be configured with the common processor.
|
||||
var meterFactory = MeterFactory.Create(mb =>
|
||||
{
|
||||
mb.SetMetricProcessor(processor);
|
||||
mb.SetMetricExporter(promExporter);
|
||||
mb.SetMetricPushInterval(TimeSpan.FromSeconds(pushIntervalInSecs));
|
||||
mb.SetMetricProcessor(processor);
|
||||
mb.SetMetricExporter(promExporter);
|
||||
mb.SetMetricPushInterval(TimeSpan.FromSeconds(pushIntervalInSecs));
|
||||
});
|
||||
|
||||
// Obtain a Meter. Libraries would pass their name as argument.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ using OpenTelemetry.Exporter.ZPages;
|
|||
using OpenTelemetry.Exporter.ZPages.Implementation;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
|
||||
namespace Samples
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace API
|
|||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
public int TemperatureF => 32 + (int)(this.TemperatureC / 0.5556);
|
||||
|
||||
public string Summary { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
|
||||
namespace LoggingTracer
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace LoggingTracer
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace LoggingTracer
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ namespace OpenTelemetry.Context
|
|||
/// <inheritdoc/>
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
return o is CorrelationContextEntry that && (this.Key == that.Key && this.Value == that.Value);
|
||||
return o is CorrelationContextEntry that && this.Key == that.Key && this.Value == that.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Internal;
|
||||
|
||||
namespace OpenTelemetry.Context
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenTelemetry.Metrics
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTelemetry.Metrics
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@
|
|||
// </copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTelemetry.Context;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Metrics
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
|
||||
namespace OpenTelemetry.Trace
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ using System;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Exporter.Jaeger.Implementation;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
|
||||
namespace OpenTelemetry.Exporter.Jaeger
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ using System.Net;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Exporter.Prometheus.Implementation;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
||||
namespace OpenTelemetry.Exporter.Prometheus
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,9 +15,6 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
|
||||
namespace OpenTelemetry.Exporter.ZPages.Implementation
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
|
|
|||
|
|
@ -16,10 +16,8 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Exporter.ZPages.Implementation;
|
||||
|
|
|
|||
|
|
@ -15,13 +15,10 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using OpenTelemetry.Exporter.ZPages.Implementation;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace OpenTelemetry.Exporter.ZPages
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ using System.Reflection;
|
|||
using System.Runtime.Remoting.Messaging;
|
||||
#endif
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OpenTelemetry.Context
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ using System;
|
|||
using System.Diagnostics.Tracing;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
|
||||
namespace OpenTelemetry.Internal
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
||||
|
|
|
|||
|
|
@ -72,43 +72,43 @@ namespace OpenTelemetry.Metrics
|
|||
boundInstrument.Status = RecordStatus.UpdatePending;
|
||||
break;
|
||||
case RecordStatus.CandidateForRemoval:
|
||||
{
|
||||
// if boundInstrument is marked for removal, then take the
|
||||
// lock to sync with Unbind() and re-add. As Collect() might have called Unbind().
|
||||
|
||||
/*
|
||||
* If Unbind gets the lock first, then it'd have removed the record.
|
||||
* But it gets added again by Bind() so no record is lost.
|
||||
* If Bind method gets this lock first, it'd promote record to UpdatePending, so that
|
||||
* Unbind will leave this record untouched.
|
||||
|
||||
* Additional notes:
|
||||
* This lock is never taken for bound instruments, and they offer the fastest performance.
|
||||
* This lock is only taken for those labelsets which are marked CandidateForRemoval.
|
||||
* It means the the 1st time a labelset is re-encountered after two Collect() has occured,
|
||||
* this lock must be taken. Subsequent usage of this labelset before the next two Collect()
|
||||
* will already have status promoted, and no lock is taken.
|
||||
* In effect, the lock is only taken for those labelsets
|
||||
* which was used once, then not used for two collect(), and then used within the subsequent
|
||||
* Collect().
|
||||
*
|
||||
* Its important to note that, for a brand new LabelSet being encountered for the 1st time, lock is not
|
||||
* taken. Lock is taken only during the 1st re-appearance of a LabelSet after a Collect period.
|
||||
*
|
||||
*/
|
||||
|
||||
lock (this.bindUnbindLock)
|
||||
{
|
||||
boundInstrument.Status = RecordStatus.UpdatePending;
|
||||
// if boundInstrument is marked for removal, then take the
|
||||
// lock to sync with Unbind() and re-add. As Collect() might have called Unbind().
|
||||
|
||||
if (!this.counterBoundInstruments.ContainsKey(labelset))
|
||||
/*
|
||||
* If Unbind gets the lock first, then it'd have removed the record.
|
||||
* But it gets added again by Bind() so no record is lost.
|
||||
* If Bind method gets this lock first, it'd promote record to UpdatePending, so that
|
||||
* Unbind will leave this record untouched.
|
||||
|
||||
* Additional notes:
|
||||
* This lock is never taken for bound instruments, and they offer the fastest performance.
|
||||
* This lock is only taken for those labelsets which are marked CandidateForRemoval.
|
||||
* It means the the 1st time a labelset is re-encountered after two Collect() has occured,
|
||||
* this lock must be taken. Subsequent usage of this labelset before the next two Collect()
|
||||
* will already have status promoted, and no lock is taken.
|
||||
* In effect, the lock is only taken for those labelsets
|
||||
* which was used once, then not used for two collect(), and then used within the subsequent
|
||||
* Collect().
|
||||
*
|
||||
* Its important to note that, for a brand new LabelSet being encountered for the 1st time, lock is not
|
||||
* taken. Lock is taken only during the 1st re-appearance of a LabelSet after a Collect period.
|
||||
*
|
||||
*/
|
||||
|
||||
lock (this.bindUnbindLock)
|
||||
{
|
||||
this.counterBoundInstruments.Add(labelset, boundInstrument);
|
||||
}
|
||||
}
|
||||
boundInstrument.Status = RecordStatus.UpdatePending;
|
||||
|
||||
break;
|
||||
}
|
||||
if (!this.counterBoundInstruments.ContainsKey(labelset))
|
||||
{
|
||||
this.counterBoundInstruments.Add(labelset, boundInstrument);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return boundInstrument;
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTelemetry.Resources;
|
||||
|
||||
namespace OpenTelemetry.Trace.Configuration
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Resources;
|
||||
|
||||
namespace OpenTelemetry.Trace.Configuration
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using OpenTelemetry.Trace.Export.Internal;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Internal;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="Intt128Test.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="Int128Test.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -414,12 +414,12 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
|
||||
var attributes = new Dictionary<string, object>
|
||||
{
|
||||
{ "stringKey", "value"},
|
||||
{ "longKey", 1L},
|
||||
{ "stringKey", "value" },
|
||||
{ "longKey", 1L },
|
||||
{ "longKey2", 1 },
|
||||
{ "doubleKey", 1D},
|
||||
{ "doubleKey2", 1F},
|
||||
{ "boolKey", true},
|
||||
{ "doubleKey", 1D },
|
||||
{ "doubleKey2", 1F },
|
||||
{ "boolKey", true },
|
||||
};
|
||||
if (additionalAttributes != null)
|
||||
{
|
||||
|
|
@ -437,34 +437,39 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
new ActivityEvent(
|
||||
"Event2",
|
||||
eventTimestamp,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
};
|
||||
|
||||
var linkedSpanId = ActivitySpanId.CreateFromString("888915b6286b9c41".AsSpan());
|
||||
|
||||
var activitySource = new ActivitySource(nameof(CreateTestActivity));
|
||||
|
||||
var tags = setAttributes ?
|
||||
attributes.Select(kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value.ToString()))
|
||||
: null;
|
||||
var links = addLinks ?
|
||||
new[]
|
||||
{
|
||||
new ActivityLink(new ActivityContext(
|
||||
traceId,
|
||||
linkedSpanId,
|
||||
ActivityTraceFlags.Recorded)),
|
||||
}
|
||||
: null;
|
||||
|
||||
var activity = activitySource.StartActivity(
|
||||
"Name",
|
||||
kind,
|
||||
parentContext: new ActivityContext(traceId, parentSpanId, ActivityTraceFlags.Recorded),
|
||||
tags: setAttributes ?
|
||||
attributes.Select(kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value.ToString()))
|
||||
: null,
|
||||
links: addLinks ?
|
||||
new[] { new ActivityLink(new ActivityContext(
|
||||
traceId,
|
||||
linkedSpanId,
|
||||
ActivityTraceFlags.Recorded)), }
|
||||
: null,
|
||||
tags,
|
||||
links,
|
||||
startTime: startTimestamp);
|
||||
|
||||
if (addEvents)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
|
@ -199,7 +198,8 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
Assert.Equal(0x1, jaegerSpan.Flags);
|
||||
|
||||
Assert.Equal(span.StartTimestamp.ToEpochMicroseconds(), jaegerSpan.StartTime);
|
||||
Assert.Equal(span.EndTimestamp.ToEpochMicroseconds()
|
||||
Assert.Equal(
|
||||
span.EndTimestamp.ToEpochMicroseconds()
|
||||
- span.StartTimestamp.ToEpochMicroseconds(), jaegerSpan.Duration);
|
||||
|
||||
var tags = jaegerSpan.Tags.ToArray();
|
||||
|
|
@ -251,7 +251,8 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
Assert.Equal(0x1, jaegerSpan.Flags);
|
||||
|
||||
Assert.Equal(span.StartTimestamp.ToEpochMicroseconds(), jaegerSpan.StartTime);
|
||||
Assert.Equal(span.EndTimestamp.ToEpochMicroseconds()
|
||||
Assert.Equal(
|
||||
span.EndTimestamp.ToEpochMicroseconds()
|
||||
- span.StartTimestamp.ToEpochMicroseconds(), jaegerSpan.Duration);
|
||||
|
||||
var tags = jaegerSpan.Tags.ToArray();
|
||||
|
|
@ -423,12 +424,12 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
|
||||
var attributes = new Dictionary<string, object>
|
||||
{
|
||||
{ "stringKey", "value"},
|
||||
{ "longKey", 1L},
|
||||
{ "stringKey", "value" },
|
||||
{ "longKey", 1L },
|
||||
{ "longKey2", 1 },
|
||||
{ "doubleKey", 1D},
|
||||
{ "doubleKey2", 1F},
|
||||
{ "boolKey", true},
|
||||
{ "doubleKey", 1D },
|
||||
{ "doubleKey2", 1F },
|
||||
{ "boolKey", true },
|
||||
};
|
||||
if (additionalAttributes != null)
|
||||
{
|
||||
|
|
@ -446,19 +447,26 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
new Event(
|
||||
"Event2",
|
||||
eventTimestamp,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
};
|
||||
|
||||
var linkedSpanId = ActivitySpanId.CreateFromString("888915b6286b9c41".AsSpan());
|
||||
var links = addLinks
|
||||
? new[]
|
||||
{
|
||||
new Link(new SpanContext(
|
||||
traceId,
|
||||
linkedSpanId,
|
||||
ActivityTraceFlags.Recorded)),
|
||||
}
|
||||
: null;
|
||||
|
||||
return new SpanData(
|
||||
"Name",
|
||||
|
|
@ -468,10 +476,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
startTimestamp,
|
||||
setAttributes ? attributes : null,
|
||||
addEvents ? events : null,
|
||||
addLinks ? new[] { new Link(new SpanContext(
|
||||
traceId,
|
||||
linkedSpanId,
|
||||
ActivityTraceFlags.Recorded)), } : null,
|
||||
links,
|
||||
resource,
|
||||
Status.Ok,
|
||||
endTimestamp);
|
||||
|
|
|
|||
|
|
@ -78,13 +78,13 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
// Assert
|
||||
Assert.Equal(2, batches.Count());
|
||||
|
||||
var PrimaryBatch = batches.Where(b => b.Process.ServiceName == "TestService");
|
||||
Assert.Single(PrimaryBatch);
|
||||
Assert.Equal(2, PrimaryBatch.First().SpanMessages.Count());
|
||||
var primaryBatch = batches.Where(b => b.Process.ServiceName == "TestService");
|
||||
Assert.Single(primaryBatch);
|
||||
Assert.Equal(2, primaryBatch.First().SpanMessages.Count());
|
||||
|
||||
var MySQLBatch = batches.Where(b => b.Process.ServiceName == "MySQL");
|
||||
Assert.Single(MySQLBatch);
|
||||
Assert.Single(MySQLBatch.First().SpanMessages);
|
||||
var mySQLBatch = batches.Where(b => b.Process.ServiceName == "MySQL");
|
||||
Assert.Single(mySQLBatch);
|
||||
Assert.Single(mySQLBatch.First().SpanMessages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -150,12 +150,12 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
var parentSpanId = ActivitySpanId.CreateFromBytes(new byte[] { 12, 23, 34, 45, 56, 67, 78, 89 });
|
||||
var attributes = new Dictionary<string, object>
|
||||
{
|
||||
{ "stringKey", "value"},
|
||||
{ "longKey", 1L},
|
||||
{ "stringKey", "value" },
|
||||
{ "longKey", 1L },
|
||||
{ "longKey2", 1 },
|
||||
{ "doubleKey", 1D},
|
||||
{ "doubleKey2", 1F},
|
||||
{ "boolKey", true},
|
||||
{ "doubleKey", 1D },
|
||||
{ "doubleKey2", 1F },
|
||||
{ "boolKey", true },
|
||||
};
|
||||
var events = new List<Event>
|
||||
{
|
||||
|
|
@ -165,16 +165,14 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
new Event(
|
||||
"Event2",
|
||||
eventTimestamp,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
};
|
||||
|
||||
var linkedSpanId = ActivitySpanId.CreateFromString("888915b6286b9c41".AsSpan());
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
|
|||
{
|
||||
public class ThriftUdpClientTransportTests : IDisposable
|
||||
{
|
||||
private MemoryStream testingMemoryStream = new MemoryStream();
|
||||
private readonly Mock<IJaegerClient> mockClient = new Mock<IJaegerClient>();
|
||||
private MemoryStream testingMemoryStream = new MemoryStream();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ProcessTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="JaegerTraceExporterTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Exporter.Jaeger.Implementation;
|
||||
using OpenTelemetry.Resources;
|
||||
using Xunit;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="SpanDataExtensionsTest.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="ActivityExtensionsTest.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -18,16 +18,12 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
using Google.Protobuf.Collections;
|
||||
|
||||
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
|
||||
|
||||
using Xunit;
|
||||
using OtlpCommon = Opentelemetry.Proto.Common.V1;
|
||||
using OtlpTrace = Opentelemetry.Proto.Trace.V1;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||
{
|
||||
public class ActivityExtensionsTest
|
||||
|
|
@ -50,8 +46,8 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
[Fact]
|
||||
public void ToOtlpResourceSpansTest()
|
||||
{
|
||||
var evenTags = new []{ new KeyValuePair<string, string>("k0", "v0") };
|
||||
var oddTags = new []{ new KeyValuePair<string, string>("k1", "v1") };
|
||||
var evenTags = new[] { new KeyValuePair<string, string>("k0", "v0") };
|
||||
var oddTags = new[] { new KeyValuePair<string, string>("k1", "v1") };
|
||||
var sources = new[]
|
||||
{
|
||||
new ActivitySource("even", "2.4.6"),
|
||||
|
|
@ -82,7 +78,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
|
||||
foreach (var instrumentationLibrarySpans in otlpResourceSpans.First().InstrumentationLibrarySpans)
|
||||
{
|
||||
Assert.Equal(numOfSpans/2, instrumentationLibrarySpans.Spans.Count);
|
||||
Assert.Equal(numOfSpans / 2, instrumentationLibrarySpans.Spans.Count);
|
||||
Assert.NotNull(instrumentationLibrarySpans.InstrumentationLibrary);
|
||||
|
||||
var expectedSpanNames = new List<string>();
|
||||
|
|
@ -155,7 +151,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
|
||||
var expectedStartTimeUnixNano = 100 * expectedUnixTimeTicks;
|
||||
Assert.Equal(expectedStartTimeUnixNano, otlpSpan.StartTimeUnixNano);
|
||||
var expectedEndTimeUnixNano = expectedStartTimeUnixNano + duration.TotalMilliseconds * 1_000_000;
|
||||
var expectedEndTimeUnixNano = expectedStartTimeUnixNano + (duration.TotalMilliseconds * 1_000_000);
|
||||
Assert.Equal(expectedEndTimeUnixNano, otlpSpan.EndTimeUnixNano);
|
||||
|
||||
var childLinks = new List<ActivityLink> { new ActivityLink(rootActivity.Context, attributes) };
|
||||
|
|
@ -226,7 +222,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
switch (originalValue)
|
||||
{
|
||||
case string s:
|
||||
Assert.Equal(akv.StringValue, s);
|
||||
Assert.Equal(akv.StringValue, s);
|
||||
break;
|
||||
case bool b:
|
||||
Assert.Equal(akv.BoolValue, b);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="SpanDataExtensionsTest.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="SpanDataExtensionsTest.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -17,21 +17,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Google.Protobuf.Collections;
|
||||
using Moq;
|
||||
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
|
||||
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
using OtlpCommon = Opentelemetry.Proto.Common.V1;
|
||||
using OtlpTrace = Opentelemetry.Proto.Trace.V1;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
||||
{
|
||||
public class SpanDataExtensionsTest
|
||||
|
|
@ -41,8 +37,8 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
{
|
||||
var spanProcessor = new Mock<SpanProcessor>();
|
||||
|
||||
var evenResource = new Resource(new []{ new KeyValuePair<string, object>("k0", "v0") });
|
||||
var oddResource = new Resource(new []{ new KeyValuePair<string, object>("k1", "v1") });
|
||||
var evenResource = new Resource(new[] { new KeyValuePair<string, object>("k0", "v0") });
|
||||
var oddResource = new Resource(new[] { new KeyValuePair<string, object>("k1", "v1") });
|
||||
var tracers = new[]
|
||||
{
|
||||
TracerFactory.Create(b => b.SetResource(evenResource)
|
||||
|
|
@ -74,7 +70,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
|
||||
var spanDataList = new List<SpanData>();
|
||||
var invocations = spanProcessor.Invocations;
|
||||
for (var i = 0; i < invocations.Count; i += 2) // Just want one of the OnStart/OnEnd pair.
|
||||
for (var i = 0; i < invocations.Count; i += 2 /* Just want one of the OnStart/OnEnd pair. */)
|
||||
{
|
||||
spanDataList.Add((SpanData)invocations[i].Arguments[0]);
|
||||
}
|
||||
|
|
@ -90,7 +86,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
foreach (var resourceSpans in otlpResourceSpans)
|
||||
{
|
||||
Assert.Single(resourceSpans.InstrumentationLibrarySpans);
|
||||
Assert.Equal(numOfSpans/2, resourceSpans.InstrumentationLibrarySpans[0].Spans.Count);
|
||||
Assert.Equal(numOfSpans / 2, resourceSpans.InstrumentationLibrarySpans[0].Spans.Count);
|
||||
Assert.NotNull(resourceSpans.Resource);
|
||||
|
||||
var expectedSpanNames = new List<string>();
|
||||
|
|
@ -130,7 +126,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
"root",
|
||||
default,
|
||||
SpanKind.Producer,
|
||||
new Status(),
|
||||
default(Status),
|
||||
startTimestamp,
|
||||
duration,
|
||||
attributes);
|
||||
|
|
@ -153,11 +149,11 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
|
||||
var expectedStartTimeUnixNano = 100 * expectedUnixTimeTicks;
|
||||
Assert.Equal(expectedStartTimeUnixNano, otlpSpan.StartTimeUnixNano);
|
||||
var expectedEndTimeUnixNano = expectedStartTimeUnixNano + duration.TotalMilliseconds * 1_000_000;
|
||||
var expectedEndTimeUnixNano = expectedStartTimeUnixNano + (duration.TotalMilliseconds * 1_000_000);
|
||||
Assert.Equal(expectedEndTimeUnixNano, otlpSpan.EndTimeUnixNano);
|
||||
|
||||
var childEvents = new [] { new Event("e0"), new Event("e1", attributes) };
|
||||
var childLinks = new [] { new Link(rootSpan.Context, attributes) };
|
||||
var childEvents = new[] { new Event("e0"), new Event("e1", attributes) };
|
||||
var childLinks = new[] { new Link(rootSpan.Context, attributes) };
|
||||
var childSpan = CreateSpanData(
|
||||
"child",
|
||||
rootSpan.Context,
|
||||
|
|
@ -186,6 +182,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
Assert.Equal(childEvents[i].Name, otlpSpan.Events[i].Name);
|
||||
AssertOtlpAttributes(childEvents[i].Attributes, otlpSpan.Events[i].Attributes);
|
||||
}
|
||||
|
||||
Assert.Equal(childLinks.Length, otlpSpan.Links.Count);
|
||||
for (var i = 0; i < childLinks.Length; i++)
|
||||
{
|
||||
|
|
@ -210,7 +207,7 @@ namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests
|
|||
switch (originalValue)
|
||||
{
|
||||
case string s:
|
||||
Assert.Equal(akv.StringValue, s);
|
||||
Assert.Equal(akv.StringValue, s);
|
||||
break;
|
||||
case bool b:
|
||||
Assert.Equal(akv.BoolValue, b);
|
||||
|
|
|
|||
|
|
@ -32,9 +32,10 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
{
|
||||
public class PrometheusExporterTests
|
||||
{
|
||||
private const int MetricPushIntervalMsec = 100;
|
||||
private const int WaitDuration = MetricPushIntervalMsec + 100;
|
||||
|
||||
private readonly ITestOutputHelper output;
|
||||
private const int metricPushIntervalMsec = 100;
|
||||
private const int waitDuration = metricPushIntervalMsec + 100;
|
||||
|
||||
public PrometheusExporterTests(ITestOutputHelper output)
|
||||
{
|
||||
|
|
@ -56,7 +57,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
}
|
||||
finally
|
||||
{
|
||||
await Task.Delay(waitDuration);
|
||||
await Task.Delay(WaitDuration);
|
||||
|
||||
var client = new HttpClient();
|
||||
var response = await client.GetAsync("http://localhost:9184/metrics/");
|
||||
|
|
@ -83,7 +84,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSingleton(promOptions);
|
||||
services.AddSingleton(promExporter); //Temporary till we figure out metrics configuration
|
||||
services.AddSingleton(promExporter); // Temporary till we figure out metrics configuration
|
||||
});
|
||||
|
||||
var server = new TestServer(builder);
|
||||
|
|
@ -98,7 +99,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
var response = await client.GetAsync("/foo");
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
|
||||
await Task.Delay(waitDuration);
|
||||
await Task.Delay(WaitDuration);
|
||||
response = await client.GetAsync("/metrics");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
var responseText = await response.Content.ReadAsStringAsync();
|
||||
|
|
@ -113,7 +114,7 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
{
|
||||
mb.SetMetricProcessor(simpleProcessor);
|
||||
mb.SetMetricExporter(exporter);
|
||||
mb.SetMetricPushInterval(TimeSpan.FromMilliseconds(metricPushIntervalMsec));
|
||||
mb.SetMetricPushInterval(TimeSpan.FromMilliseconds(MetricPushIntervalMsec));
|
||||
}).GetMeter("library1");
|
||||
|
||||
var testCounter = meter.CreateInt64Counter("testCounter");
|
||||
|
|
@ -154,12 +155,16 @@ namespace OpenTelemetry.Exporter.Prometheus.Tests
|
|||
|
||||
// Validate measure.
|
||||
Assert.Contains("# TYPE testMeasure summary", responseText);
|
||||
|
||||
// sum is 6150 = 10 * (10+100+5+500)
|
||||
Assert.Contains("testMeasure_sum{dim1=\"value1\"} 6150", responseText);
|
||||
|
||||
// count is 10 * 4
|
||||
Assert.Contains("testMeasure_count{dim1=\"value1\"} 40", responseText);
|
||||
|
||||
// Min is 5
|
||||
Assert.Contains("testMeasure{dim1=\"value1\",quantile=\"0\"} 5", responseText);
|
||||
|
||||
// Max is 500
|
||||
Assert.Contains("testMeasure{dim1=\"value1\",quantile=\"1\"} 500", responseText);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ZipkinSpanConverterTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="ZipkinTraceExporterRemoteEndpointTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -91,12 +91,12 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests.Implementation
|
|||
|
||||
var attributes = new Dictionary<string, object>
|
||||
{
|
||||
{ "stringKey", "value"},
|
||||
{ "longKey", 1L},
|
||||
{ "stringKey", "value" },
|
||||
{ "longKey", 1L },
|
||||
{ "longKey2", 1 },
|
||||
{ "doubleKey", 1D},
|
||||
{ "doubleKey2", 1F},
|
||||
{ "boolKey", true},
|
||||
{ "doubleKey", 1D },
|
||||
{ "doubleKey2", 1F },
|
||||
{ "boolKey", true },
|
||||
};
|
||||
if (additionalAttributes != null)
|
||||
{
|
||||
|
|
@ -114,20 +114,26 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests.Implementation
|
|||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
new Event(
|
||||
"Event2",
|
||||
eventTimestamp,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "key", "value" },
|
||||
}
|
||||
),
|
||||
}),
|
||||
};
|
||||
|
||||
var linkedSpanId = ActivitySpanId.CreateFromString("888915b6286b9c41".AsSpan());
|
||||
|
||||
var links = addLinks
|
||||
? new[]
|
||||
{
|
||||
new Link(new SpanContext(
|
||||
traceId,
|
||||
linkedSpanId,
|
||||
ActivityTraceFlags.Recorded)),
|
||||
}
|
||||
: null;
|
||||
return new SpanData(
|
||||
"Name",
|
||||
new SpanContext(traceId, spanId, ActivityTraceFlags.Recorded),
|
||||
|
|
@ -136,10 +142,7 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests.Implementation
|
|||
startTimestamp,
|
||||
setAttributes ? attributes : null,
|
||||
addEvents ? events : null,
|
||||
addLinks ? new[] { new Link(new SpanContext(
|
||||
traceId,
|
||||
linkedSpanId,
|
||||
ActivityTraceFlags.Recorded)), } : null,
|
||||
links,
|
||||
null,
|
||||
Status.Ok,
|
||||
endTimestamp);
|
||||
|
|
@ -21,9 +21,9 @@ using System.Net;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Exporter.Zipkin.Implementation;
|
||||
using OpenTelemetry.Exporter.Zipkin.Tests.Implementation;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -89,9 +89,14 @@ namespace OpenTelemetry.Exporter.Zipkin.Tests
|
|||
|
||||
StringBuilder ipInformation = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(exporter.LocalEndpoint.Ipv4))
|
||||
{
|
||||
ipInformation.Append($@",""ipv4"":""{exporter.LocalEndpoint.Ipv4}""");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(exporter.LocalEndpoint.Ipv6))
|
||||
{
|
||||
ipInformation.Append($@",""ipv6"":""{exporter.LocalEndpoint.Ipv6}""");
|
||||
}
|
||||
|
||||
Assert.Equal(
|
||||
$@"[{{""traceId"":""e8ea7e9ac72de94e91fabc613f9686b2"",""name"":""Name"",""parentId"":""{ZipkinConversionExtensions.EncodeSpanId(span.ParentSpanId)}"",""id"":""{ZipkinConversionExtensions.EncodeSpanId(context.SpanId)}"",""kind"":""CLIENT"",""timestamp"":{timestamp},""duration"":60000000,""localEndpoint"":{{""serviceName"":""Open Telemetry Exporter""{ipInformation}}},""annotations"":[{{""timestamp"":{timestamp},""value"":""Event1""}},{{""timestamp"":{timestamp},""value"":""Event2""}}],""tags"":{{""stringKey"":""value"",""longKey"":""1"",""longKey2"":""1"",""doubleKey"":""1"",""doubleKey2"":""1"",""boolKey"":""True"",""ot.status_code"":""Ok""}}}}]",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="StackExchangeRedisCallsInstrumentationTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="HostingIntegrationTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -14,16 +14,16 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Extensions.Hosting
|
||||
{
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using Xunit;
|
||||
|
||||
public class HostingIntegrationTests
|
||||
{
|
||||
[Fact]
|
||||
|
|
@ -116,7 +116,7 @@ namespace OpenTelemetry.Extensions.Hosting
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
Disposed = true;
|
||||
this.Disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,24 +14,24 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using Xunit;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Moq;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using OpenTelemetry.Trace.Samplers;
|
||||
using TestApp.AspNetCore._3._1;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
||||
{
|
||||
|
|
@ -74,7 +74,6 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
builder.ConfigureTestServices(ConfigureTestServices))
|
||||
.CreateClient())
|
||||
{
|
||||
|
||||
// Act
|
||||
var response = await client.GetAsync("/api/values");
|
||||
|
||||
|
|
@ -178,7 +177,6 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
Assert.Equal(expectedSpanId, span.ParentSpanId);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task FilterOutRequest()
|
||||
{
|
||||
|
|
@ -198,6 +196,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
builder.ConfigureTestServices(ConfigureTestServices)))
|
||||
{
|
||||
using var client = testFactory.CreateClient();
|
||||
|
||||
// Act
|
||||
var response1 = await client.GetAsync("/api/values");
|
||||
var response2 = await client.GetAsync("/api/values/2");
|
||||
|
|
@ -222,7 +221,8 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
// We need to let End callback execute as it is executed AFTER response was returned.
|
||||
// In unit tests environment there may be a lot of parallel unit tests executed, so
|
||||
// giving some breezing room for the End callback to complete
|
||||
Assert.True(SpinWait.SpinUntil(() =>
|
||||
Assert.True(SpinWait.SpinUntil(
|
||||
() =>
|
||||
{
|
||||
Thread.Sleep(10);
|
||||
return spanProcessor.Invocations.Count >= 2;
|
||||
|
|
|
|||
|
|
@ -14,18 +14,18 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using Xunit;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Moq;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Moq;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using TestApp.AspNetCore._3._1;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
||||
{
|
||||
|
|
@ -37,18 +37,6 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
public IncomingRequestsCollectionsIsAccordingToTheSpecTests(WebApplicationFactory<Startup> factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
|
||||
}
|
||||
|
||||
public class TestCallbackMiddlewareImpl : CallbackMiddleware.CallbackMiddlewareImpl
|
||||
{
|
||||
|
||||
public override async Task<bool> ProcessAsync(HttpContext context)
|
||||
{
|
||||
context.Response.StatusCode = 503;
|
||||
await context.Response.WriteAsync("empty");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -69,7 +57,6 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
}))
|
||||
.CreateClient())
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
// Act
|
||||
|
|
@ -101,5 +88,15 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Tests
|
|||
Assert.Equal("/api/values", span.Attributes.GetValue("http.path"));
|
||||
Assert.Equal(503L, span.Attributes.GetValue("http.status_code"));
|
||||
}
|
||||
|
||||
public class TestCallbackMiddlewareImpl : CallbackMiddleware.CallbackMiddlewareImpl
|
||||
{
|
||||
public override async Task<bool> ProcessAsync(HttpContext context)
|
||||
{
|
||||
context.Response.StatusCode = 503;
|
||||
await context.Response.WriteAsync("empty");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,18 +14,18 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
#if NETCOREAPP3_1
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using Moq;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
|
|
@ -250,8 +250,8 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
using var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));
|
||||
try
|
||||
{
|
||||
await c.PostAsync("https://dc.services.visualstudio.com/", new StringContent(""), cts.Token);
|
||||
await c.PostAsync("https://localhost:9411/api/v2/spans", new StringContent(""), cts.Token);
|
||||
await c.PostAsync("https://dc.services.visualstudio.com/", new StringContent(string.Empty), cts.Token);
|
||||
await c.PostAsync("https://localhost:9411/api/v2/spans", new StringContent(string.Empty), cts.Token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="DurationTest.netcore31.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="HttpClientTests.netcore31.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -14,12 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
#if NETCOREAPP3_1
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
|
@ -27,6 +21,12 @@ using System.Linq;
|
|||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
|
|
@ -80,7 +80,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//test case can intentionally send request that will result in exception
|
||||
// test case can intentionally send request that will result in exception
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,28 +92,30 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
|
||||
var d = new Dictionary<StatusCanonicalCode, string>()
|
||||
{
|
||||
{ StatusCanonicalCode.Ok, "OK"},
|
||||
{ StatusCanonicalCode.Cancelled, "CANCELLED"},
|
||||
{ StatusCanonicalCode.Unknown, "UNKNOWN"},
|
||||
{ StatusCanonicalCode.InvalidArgument, "INVALID_ARGUMENT"},
|
||||
{ StatusCanonicalCode.DeadlineExceeded, "DEADLINE_EXCEEDED"},
|
||||
{ StatusCanonicalCode.NotFound, "NOT_FOUND"},
|
||||
{ StatusCanonicalCode.AlreadyExists, "ALREADY_EXISTS"},
|
||||
{ StatusCanonicalCode.PermissionDenied, "PERMISSION_DENIED"},
|
||||
{ StatusCanonicalCode.ResourceExhausted, "RESOURCE_EXHAUSTED"},
|
||||
{ StatusCanonicalCode.FailedPrecondition, "FAILED_PRECONDITION"},
|
||||
{ StatusCanonicalCode.Aborted, "ABORTED"},
|
||||
{ StatusCanonicalCode.OutOfRange, "OUT_OF_RANGE"},
|
||||
{ StatusCanonicalCode.Unimplemented, "UNIMPLEMENTED"},
|
||||
{ StatusCanonicalCode.Internal, "INTERNAL"},
|
||||
{ StatusCanonicalCode.Unavailable, "UNAVAILABLE"},
|
||||
{ StatusCanonicalCode.DataLoss, "DATA_LOSS"},
|
||||
{ StatusCanonicalCode.Unauthenticated, "UNAUTHENTICATED"},
|
||||
{ StatusCanonicalCode.Ok, "OK" },
|
||||
{ StatusCanonicalCode.Cancelled, "CANCELLED" },
|
||||
{ StatusCanonicalCode.Unknown, "UNKNOWN" },
|
||||
{ StatusCanonicalCode.InvalidArgument, "INVALID_ARGUMENT" },
|
||||
{ StatusCanonicalCode.DeadlineExceeded, "DEADLINE_EXCEEDED" },
|
||||
{ StatusCanonicalCode.NotFound, "NOT_FOUND" },
|
||||
{ StatusCanonicalCode.AlreadyExists, "ALREADY_EXISTS" },
|
||||
{ StatusCanonicalCode.PermissionDenied, "PERMISSION_DENIED" },
|
||||
{ StatusCanonicalCode.ResourceExhausted, "RESOURCE_EXHAUSTED" },
|
||||
{ StatusCanonicalCode.FailedPrecondition, "FAILED_PRECONDITION" },
|
||||
{ StatusCanonicalCode.Aborted, "ABORTED" },
|
||||
{ StatusCanonicalCode.OutOfRange, "OUT_OF_RANGE" },
|
||||
{ StatusCanonicalCode.Unimplemented, "UNIMPLEMENTED" },
|
||||
{ StatusCanonicalCode.Internal, "INTERNAL" },
|
||||
{ StatusCanonicalCode.Unavailable, "UNAVAILABLE" },
|
||||
{ StatusCanonicalCode.DataLoss, "DATA_LOSS" },
|
||||
{ StatusCanonicalCode.Unauthenticated, "UNAUTHENTICATED" },
|
||||
};
|
||||
|
||||
Assert.Equal(tc.SpanStatus, d[span.Status.CanonicalCode]);
|
||||
if (tc.SpanStatusHasDescription.HasValue)
|
||||
{
|
||||
Assert.Equal(tc.SpanStatusHasDescription.Value, !string.IsNullOrEmpty(span.Status.Description));
|
||||
}
|
||||
|
||||
var normalizedAttributes = span.Attributes.ToDictionary(x => x.Key, x => x.Value.ToString());
|
||||
tc.SpanAttributes = tc.SpanAttributes.ToDictionary(x => x.Key, x => HttpTestData.NormalizeValues(x.Value, host, port));
|
||||
|
|
@ -146,7 +148,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
]
|
||||
")));
|
||||
|
||||
var t = (Task)this.GetType().InvokeMember(nameof(HttpOutCallsAreCollectedSuccessfullyAsync), BindingFlags.InvokeMethod, null, this, HttpTestData.GetArgumentsFromTestCaseObject(input).First());
|
||||
var t = (Task)this.GetType().InvokeMember(nameof(this.HttpOutCallsAreCollectedSuccessfullyAsync), BindingFlags.InvokeMethod, null, this, HttpTestData.GetArgumentsFromTestCaseObject(input).First());
|
||||
await t;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,44 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
{
|
||||
public static class HttpTestData
|
||||
{
|
||||
public static IEnumerable<object[]> ReadTestCases()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var serializer = new JsonSerializer();
|
||||
var input = serializer.Deserialize<HttpOutTestCase[]>(new JsonTextReader(new StreamReader(assembly.GetManifestResourceStream("OpenTelemetry.Instrumentation.Dependencies.Tests.http-out-test-cases.json"))));
|
||||
|
||||
return GetArgumentsFromTestCaseObject(input);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetArgumentsFromTestCaseObject(IEnumerable<HttpOutTestCase> input)
|
||||
{
|
||||
var result = new List<object[]>();
|
||||
|
||||
foreach (var testCase in input)
|
||||
{
|
||||
result.Add(new object[]
|
||||
{
|
||||
testCase,
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string NormalizeValues(string value, string host, int port)
|
||||
{
|
||||
return value.Replace("{host}", host).Replace("{port}", port.ToString());
|
||||
}
|
||||
|
||||
public class HttpOutTestCase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
|
@ -46,33 +75,5 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
|
||||
public bool SetHttpFlavor { get; set; }
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ReadTestCases()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var serializer = new JsonSerializer();
|
||||
var input = serializer.Deserialize<HttpOutTestCase[]>(new JsonTextReader(new StreamReader(assembly.GetManifestResourceStream("OpenTelemetry.Instrumentation.Dependencies.Tests.http-out-test-cases.json"))));
|
||||
|
||||
return GetArgumentsFromTestCaseObject(input);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetArgumentsFromTestCaseObject(IEnumerable<HttpOutTestCase> input)
|
||||
{
|
||||
var result = new List<object[]>();
|
||||
|
||||
foreach (var testCase in input)
|
||||
{
|
||||
result.Add(new object[] {
|
||||
testCase,
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string NormalizeValues(string value, string host, int port)
|
||||
{
|
||||
return value.Replace("{host}", host).Replace("{port}", port.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
// </copyright>
|
||||
#if NET461
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -24,26 +24,25 @@ using System.Net;
|
|||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
{
|
||||
public class HttpWebRequestActivitySourceTests : IDisposable
|
||||
{
|
||||
static HttpWebRequestActivitySourceTests()
|
||||
{
|
||||
GC.KeepAlive(HttpWebRequestActivitySource.Instance);
|
||||
}
|
||||
|
||||
private readonly IDisposable testServer;
|
||||
private readonly string testServerHost;
|
||||
private readonly int testServerPort;
|
||||
private readonly string hostNameAndPort;
|
||||
|
||||
static HttpWebRequestActivitySourceTests()
|
||||
{
|
||||
GC.KeepAlive(HttpWebRequestActivitySource.Instance);
|
||||
}
|
||||
|
||||
public HttpWebRequestActivitySourceTests()
|
||||
{
|
||||
Assert.Null(Activity.Current);
|
||||
|
|
@ -88,6 +87,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
{
|
||||
context.Response.StatusCode = 200;
|
||||
}
|
||||
|
||||
if (context.Response.StatusCode != 204)
|
||||
{
|
||||
using StreamWriter writeStream = new StreamWriter(context.Response.OutputStream);
|
||||
|
|
@ -122,6 +122,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
listenerFound = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
};
|
||||
|
|
@ -256,118 +257,136 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
|
||||
using var eventRecords = new ActivitySourceRecorder();
|
||||
|
||||
// Send a random Http request to generate some events
|
||||
var webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
if (method == "POST")
|
||||
{
|
||||
// Send a random Http request to generate some events
|
||||
var webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
webRequest.Method = method;
|
||||
|
||||
if (method == "POST")
|
||||
Stream stream = null;
|
||||
switch (mode)
|
||||
{
|
||||
webRequest.Method = method;
|
||||
|
||||
Stream stream = null;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
stream = webRequest.GetRequestStream();
|
||||
break;
|
||||
case 1:
|
||||
stream = await webRequest.GetRequestStreamAsync();
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
object state = new object();
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
IAsyncResult asyncResult = webRequest.BeginGetRequestStream(ar =>
|
||||
case 0:
|
||||
stream = webRequest.GetRequestStream();
|
||||
break;
|
||||
case 1:
|
||||
stream = await webRequest.GetRequestStreamAsync();
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
object state = new object();
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
IAsyncResult asyncResult = webRequest.BeginGetRequestStream(
|
||||
ar =>
|
||||
{
|
||||
Assert.Equal(state, ar.AsyncState);
|
||||
handle.Set();
|
||||
},
|
||||
state);
|
||||
stream = webRequest.EndGetRequestStream(asyncResult);
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
throw new InvalidOperationException();
|
||||
handle.Dispose();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
stream = webRequest.EndGetRequestStream(asyncResult);
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
{
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
object state = new object();
|
||||
webRequest.BeginGetRequestStream(ar =>
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
object state = new object();
|
||||
webRequest.BeginGetRequestStream(
|
||||
ar =>
|
||||
{
|
||||
stream = webRequest.EndGetRequestStream(ar);
|
||||
Assert.Equal(state, ar.AsyncState);
|
||||
handle.Set();
|
||||
},
|
||||
state);
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
throw new InvalidOperationException();
|
||||
handle.Dispose();
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
Assert.NotNull(stream);
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
using StreamWriter writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine("hello world");
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
WebResponse webResponse = null;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
webResponse = webRequest.GetResponse();
|
||||
break;
|
||||
case 1:
|
||||
webResponse = await webRequest.GetResponseAsync();
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
object state = new object();
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
IAsyncResult asyncResult = webRequest.BeginGetResponse(ar =>
|
||||
Assert.NotNull(stream);
|
||||
|
||||
using StreamWriter writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine("hello world");
|
||||
}
|
||||
|
||||
WebResponse webResponse = null;
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
webResponse = webRequest.GetResponse();
|
||||
break;
|
||||
case 1:
|
||||
webResponse = await webRequest.GetResponseAsync();
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
object state = new object();
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
IAsyncResult asyncResult = webRequest.BeginGetResponse(
|
||||
ar =>
|
||||
{
|
||||
Assert.Equal(state, ar.AsyncState);
|
||||
handle.Set();
|
||||
},
|
||||
state);
|
||||
webResponse = webRequest.EndGetResponse(asyncResult);
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
throw new InvalidOperationException();
|
||||
handle.Dispose();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
webResponse = webRequest.EndGetResponse(asyncResult);
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
{
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
object state = new object();
|
||||
webRequest.BeginGetResponse(ar =>
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
using EventWaitHandle handle = new EventWaitHandle(false, EventResetMode.ManualReset);
|
||||
object state = new object();
|
||||
webRequest.BeginGetResponse(
|
||||
ar =>
|
||||
{
|
||||
webResponse = webRequest.EndGetResponse(ar);
|
||||
Assert.Equal(state, ar.AsyncState);
|
||||
handle.Set();
|
||||
},
|
||||
state);
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
throw new InvalidOperationException();
|
||||
handle.Dispose();
|
||||
if (!handle.WaitOne(TimeSpan.FromSeconds(30)))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
Assert.NotNull(webResponse);
|
||||
handle.Dispose();
|
||||
}
|
||||
|
||||
using StreamReader reader = new StreamReader(webResponse.GetResponseStream());
|
||||
|
||||
reader.ReadToEnd(); // Make sure response is not disposed.
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
Assert.NotNull(webResponse);
|
||||
|
||||
using StreamReader reader = new StreamReader(webResponse.GetResponseStream());
|
||||
|
||||
reader.ReadToEnd(); // Make sure response is not disposed.
|
||||
|
||||
// We should have exactly one Start and one Stop event
|
||||
Assert.Equal(2, eventRecords.Records.Count);
|
||||
Assert.Equal(1, eventRecords.Records.Count(rec => rec.Key == "Start"));
|
||||
|
|
@ -681,7 +700,6 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
return method == "GET"
|
||||
? client.GetAsync(url)
|
||||
: client.PostAsync(url, new StringContent("hello world"));
|
||||
|
||||
});
|
||||
Assert.True(ex is HttpRequestException);
|
||||
}
|
||||
|
|
@ -730,6 +748,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
Assert.Contains("bad%2Fkey=value", correlationContext);
|
||||
Assert.Contains("goodkey=bad%2Fvalue", correlationContext);
|
||||
}
|
||||
|
||||
parentActivity.Stop();
|
||||
}
|
||||
|
||||
|
|
@ -847,19 +866,6 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private string BuildRequestUrl(bool useHttps = false, string path = "echo", string queryString = null)
|
||||
{
|
||||
return $"{(useHttps ? "https" : "http")}://{this.testServerHost}:{this.testServerPort}/{path}{(string.IsNullOrWhiteSpace(queryString) ? string.Empty : $"?{queryString}")}";
|
||||
}
|
||||
|
||||
private void CleanUpActivity()
|
||||
{
|
||||
while (Activity.Current != null)
|
||||
{
|
||||
Activity.Current.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static (Activity, HttpWebRequest) AssertFirstEventWasStart(ActivitySourceRecorder eventRecords)
|
||||
{
|
||||
Assert.True(eventRecords.Records.TryDequeue(out KeyValuePair<string, Activity> startEvent));
|
||||
|
|
@ -883,7 +889,10 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
Assert.Equal("http", activity.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.ComponentKey).Value);
|
||||
Assert.Equal(method, activity.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpMethodKey).Value);
|
||||
if (hostNameAndPort != null)
|
||||
{
|
||||
Assert.Equal(hostNameAndPort, activity.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpHostKey).Value);
|
||||
}
|
||||
|
||||
Assert.Equal(url, activity.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpUrlKey).Value);
|
||||
Assert.Equal("1.1", activity.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpFlavorKey).Value);
|
||||
}
|
||||
|
|
@ -894,20 +903,34 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
Assert.Equal(statusText, activity.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.StatusDescriptionKey).Value);
|
||||
}
|
||||
|
||||
private string BuildRequestUrl(bool useHttps = false, string path = "echo", string queryString = null)
|
||||
{
|
||||
return $"{(useHttps ? "https" : "http")}://{this.testServerHost}:{this.testServerPort}/{path}{(string.IsNullOrWhiteSpace(queryString) ? string.Empty : $"?{queryString}")}";
|
||||
}
|
||||
|
||||
private void CleanUpActivity()
|
||||
{
|
||||
while (Activity.Current != null)
|
||||
{
|
||||
Activity.Current.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ActivitySourceRecorder"/> is a helper class for recording <see cref="HttpWebRequestActivitySource.ActivitySourceName"/> events.
|
||||
/// </summary>
|
||||
private class ActivitySourceRecorder : IDisposable
|
||||
{
|
||||
private readonly Action<KeyValuePair<string, Activity>> onEvent;
|
||||
private readonly ActivityListener activityListener;
|
||||
|
||||
public ActivitySourceRecorder(Action<KeyValuePair<string, Activity>> onEvent = null, ActivityDataRequest activityDataRequest = ActivityDataRequest.AllDataAndRecorded)
|
||||
{
|
||||
this.activityListener = new ActivityListener
|
||||
{
|
||||
ShouldListenTo = (activitySource) => activitySource.Name == HttpWebRequestActivitySource.ActivitySourceName,
|
||||
ActivityStarted = ActivityStarted,
|
||||
ActivityStopped = ActivityStopped,
|
||||
ActivityStarted = this.ActivityStarted,
|
||||
ActivityStopped = this.ActivityStopped,
|
||||
GetRequestedDataUsingContext = (ref ActivityCreationOptions<ActivityContext> options) => activityDataRequest,
|
||||
};
|
||||
|
||||
|
|
@ -916,13 +939,13 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
this.onEvent = onEvent;
|
||||
}
|
||||
|
||||
public ConcurrentQueue<KeyValuePair<string, Activity>> Records { get; } = new ConcurrentQueue<KeyValuePair<string, Activity>>();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.activityListener.Dispose();
|
||||
}
|
||||
|
||||
public ConcurrentQueue<KeyValuePair<string, Activity>> Records { get; } = new ConcurrentQueue<KeyValuePair<string, Activity>>();
|
||||
|
||||
public void ActivityStarted(Activity activity) => this.Record("Start", activity);
|
||||
|
||||
public void ActivityStopped(Activity activity) => this.Record("Stop", activity);
|
||||
|
|
@ -934,8 +957,6 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
this.Records.Enqueue(record);
|
||||
this.onEvent?.Invoke(record);
|
||||
}
|
||||
|
||||
private readonly ActivityListener activityListener;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ using System.Net.Http;
|
|||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using OpenTelemetry.Internal.Test;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using OpenTelemetry.Instrumentation.Dependencies.Implementation;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//test case can intentionally send request that will result in exception
|
||||
// test case can intentionally send request that will result in exception
|
||||
}
|
||||
|
||||
Assert.Equal(2, activityProcessor.Invocations.Count); // begin and end was called
|
||||
|
|
@ -89,23 +89,23 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
|
||||
var d = new Dictionary<string, string>()
|
||||
{
|
||||
{ StatusCanonicalCode.Ok.ToString(), "OK"},
|
||||
{ StatusCanonicalCode.Cancelled.ToString(), "CANCELLED"},
|
||||
{ StatusCanonicalCode.Unknown.ToString(), "UNKNOWN"},
|
||||
{ StatusCanonicalCode.InvalidArgument.ToString(), "INVALID_ARGUMENT"},
|
||||
{ StatusCanonicalCode.DeadlineExceeded.ToString(), "DEADLINE_EXCEEDED"},
|
||||
{ StatusCanonicalCode.NotFound.ToString(), "NOT_FOUND"},
|
||||
{ StatusCanonicalCode.AlreadyExists.ToString(), "ALREADY_EXISTS"},
|
||||
{ StatusCanonicalCode.PermissionDenied.ToString(), "PERMISSION_DENIED"},
|
||||
{ StatusCanonicalCode.ResourceExhausted.ToString(), "RESOURCE_EXHAUSTED"},
|
||||
{ StatusCanonicalCode.FailedPrecondition.ToString(), "FAILED_PRECONDITION"},
|
||||
{ StatusCanonicalCode.Aborted.ToString(), "ABORTED"},
|
||||
{ StatusCanonicalCode.OutOfRange.ToString(), "OUT_OF_RANGE"},
|
||||
{ StatusCanonicalCode.Unimplemented.ToString(), "UNIMPLEMENTED"},
|
||||
{ StatusCanonicalCode.Internal.ToString(), "INTERNAL"},
|
||||
{ StatusCanonicalCode.Unavailable.ToString(), "UNAVAILABLE"},
|
||||
{ StatusCanonicalCode.DataLoss.ToString(), "DATA_LOSS"},
|
||||
{ StatusCanonicalCode.Unauthenticated.ToString(), "UNAUTHENTICATED"},
|
||||
{ StatusCanonicalCode.Ok.ToString(), "OK" },
|
||||
{ StatusCanonicalCode.Cancelled.ToString(), "CANCELLED" },
|
||||
{ StatusCanonicalCode.Unknown.ToString(), "UNKNOWN" },
|
||||
{ StatusCanonicalCode.InvalidArgument.ToString(), "INVALID_ARGUMENT" },
|
||||
{ StatusCanonicalCode.DeadlineExceeded.ToString(), "DEADLINE_EXCEEDED" },
|
||||
{ StatusCanonicalCode.NotFound.ToString(), "NOT_FOUND" },
|
||||
{ StatusCanonicalCode.AlreadyExists.ToString(), "ALREADY_EXISTS" },
|
||||
{ StatusCanonicalCode.PermissionDenied.ToString(), "PERMISSION_DENIED" },
|
||||
{ StatusCanonicalCode.ResourceExhausted.ToString(), "RESOURCE_EXHAUSTED" },
|
||||
{ StatusCanonicalCode.FailedPrecondition.ToString(), "FAILED_PRECONDITION" },
|
||||
{ StatusCanonicalCode.Aborted.ToString(), "ABORTED" },
|
||||
{ StatusCanonicalCode.OutOfRange.ToString(), "OUT_OF_RANGE" },
|
||||
{ StatusCanonicalCode.Unimplemented.ToString(), "UNIMPLEMENTED" },
|
||||
{ StatusCanonicalCode.Internal.ToString(), "INTERNAL" },
|
||||
{ StatusCanonicalCode.Unavailable.ToString(), "UNAVAILABLE" },
|
||||
{ StatusCanonicalCode.DataLoss.ToString(), "DATA_LOSS" },
|
||||
{ StatusCanonicalCode.Unauthenticated.ToString(), "UNAUTHENTICATED" },
|
||||
};
|
||||
|
||||
tc.SpanAttributes = tc.SpanAttributes.ToDictionary(
|
||||
|
|
@ -113,7 +113,10 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
x =>
|
||||
{
|
||||
if (x.Key == "http.flavor" && x.Value == "2.0")
|
||||
{
|
||||
return "1.1";
|
||||
}
|
||||
|
||||
return HttpTestData.NormalizeValues(x.Value, host, port);
|
||||
});
|
||||
|
||||
|
|
@ -128,22 +131,29 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
{
|
||||
Assert.Equal(value, tag.Value);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tag.Key == SpanAttributeConstants.StatusCodeKey)
|
||||
{
|
||||
Assert.Equal(tc.SpanStatus, d[tag.Value]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tag.Key == SpanAttributeConstants.StatusDescriptionKey)
|
||||
{
|
||||
if (tc.SpanStatusHasDescription.HasValue)
|
||||
{
|
||||
Assert.Equal(tc.SpanStatusHasDescription.Value, !string.IsNullOrEmpty(tag.Value));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Assert.True(false, $"Tag {tag.Key} was not found in test data.");
|
||||
}
|
||||
|
||||
Assert.Equal(value, tag.Value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,25 +111,29 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
Assert.Equal(StatusCanonicalCode.Ok, span.Status.CanonicalCode);
|
||||
Assert.Null(span.Status.Description);
|
||||
|
||||
Assert.Equal("sql", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.ComponentKey).Value as string);
|
||||
Assert.Equal("sql", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseTypeKey).Value as string);
|
||||
Assert.Equal("master", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseInstanceKey).Value as string);
|
||||
Assert.Equal(
|
||||
"sql",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.ComponentKey).Value as string);
|
||||
Assert.Equal(
|
||||
"sql",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseTypeKey).Value as string);
|
||||
Assert.Equal(
|
||||
"master",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseInstanceKey).Value as string);
|
||||
|
||||
switch (commandType)
|
||||
{
|
||||
case CommandType.StoredProcedure:
|
||||
if (captureStoredProcedureCommandName)
|
||||
{
|
||||
Assert.Equal(commandText, span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
Assert.Equal(
|
||||
commandText,
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Null(span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
Assert.Null(
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -137,8 +141,9 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
case CommandType.Text:
|
||||
if (captureTextCommandContent)
|
||||
{
|
||||
Assert.Equal(commandText, span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
Assert.Equal(
|
||||
commandText,
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -149,8 +154,9 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
break;
|
||||
}
|
||||
|
||||
Assert.Equal("(localdb)\\MSSQLLocalDB", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.PeerServiceKey).Value as string);
|
||||
Assert.Equal(
|
||||
"(localdb)\\MSSQLLocalDB",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.PeerServiceKey).Value as string);
|
||||
|
||||
activity.Stop();
|
||||
}
|
||||
|
|
@ -209,16 +215,21 @@ namespace OpenTelemetry.Instrumentation.Dependencies.Tests
|
|||
Assert.Equal(StatusCanonicalCode.Unknown, span.Status.CanonicalCode);
|
||||
Assert.Equal("Boom!", span.Status.Description);
|
||||
|
||||
Assert.Equal("sql", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.ComponentKey).Value as string);
|
||||
Assert.Equal("sql", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseTypeKey).Value as string);
|
||||
Assert.Equal("master", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseInstanceKey).Value as string);
|
||||
Assert.Equal("SP_GetOrders", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
Assert.Equal("(localdb)\\MSSQLLocalDB", span.Attributes.FirstOrDefault(i =>
|
||||
i.Key == SpanAttributeConstants.PeerServiceKey).Value as string);
|
||||
Assert.Equal(
|
||||
"sql",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.ComponentKey).Value as string);
|
||||
Assert.Equal(
|
||||
"sql",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseTypeKey).Value as string);
|
||||
Assert.Equal(
|
||||
"master",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseInstanceKey).Value as string);
|
||||
Assert.Equal(
|
||||
"SP_GetOrders",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.DatabaseStatementKey).Value as string);
|
||||
Assert.Equal(
|
||||
"(localdb)\\MSSQLLocalDB",
|
||||
span.Attributes.FirstOrDefault(i => i.Key == SpanAttributeConstants.PeerServiceKey).Value as string);
|
||||
|
||||
activity.Stop();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Tests
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="StackExchangeRedisCallsInstrumentationTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="RedisProfilerEntryToSpanConverterTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
|
||||
using System;
|
||||
using Moq;
|
||||
using OpenTelemetry.Instrumentation.StackExchangeRedis.Tests;
|
||||
|
|
@ -31,7 +30,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation
|
|||
|
||||
public RedisProfilerEntryToSpanConverterTests()
|
||||
{
|
||||
tracer = TracerFactory.Create(b => { }).GetTracer(null);
|
||||
this.tracer = TracerFactory.Create(b => { }).GetTracer(null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -42,7 +41,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation
|
|||
profiledCommand.Setup(m => m.CommandCreated).Returns(DateTime.UtcNow);
|
||||
profiledCommand.Setup(m => m.Command).Returns("SET");
|
||||
|
||||
var result = (SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(tracer, null, profiledCommand.Object);
|
||||
var result = (SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object);
|
||||
Assert.Equal("SET", result.Name);
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +51,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation
|
|||
var profiledCommand = new Mock<IProfiledCommand>();
|
||||
var now = DateTimeOffset.Now;
|
||||
profiledCommand.Setup(m => m.CommandCreated).Returns(now.DateTime);
|
||||
var result = ((SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object));
|
||||
var result = (SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object);
|
||||
Assert.Equal(now, result.StartTimestamp);
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +60,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation
|
|||
{
|
||||
var profiledCommand = new Mock<IProfiledCommand>();
|
||||
profiledCommand.Setup(m => m.CommandCreated).Returns(DateTime.UtcNow);
|
||||
var result = ((SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object));
|
||||
var result = (SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object);
|
||||
Assert.Contains(result.Attributes, kvp => kvp.Key == "db.type");
|
||||
Assert.Equal("redis", result.Attributes.GetValue("db.type"));
|
||||
}
|
||||
|
|
@ -72,7 +71,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation
|
|||
var profiledCommand = new Mock<IProfiledCommand>();
|
||||
profiledCommand.Setup(m => m.CommandCreated).Returns(DateTime.UtcNow);
|
||||
profiledCommand.Setup(m => m.Command).Returns("SET");
|
||||
var result = ((SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object));
|
||||
var result = (SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object);
|
||||
Assert.Contains(result.Attributes, kvp => kvp.Key == "db.statement");
|
||||
Assert.Equal("SET", result.Attributes.GetValue("db.statement"));
|
||||
}
|
||||
|
|
@ -85,7 +84,7 @@ namespace OpenTelemetry.Instrumentation.StackExchangeRedis.Implementation
|
|||
var expectedFlags = StackExchange.Redis.CommandFlags.FireAndForget |
|
||||
StackExchange.Redis.CommandFlags.NoRedirect;
|
||||
profiledCommand.Setup(m => m.Flags).Returns(expectedFlags);
|
||||
var result = ((SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object));
|
||||
var result = (SpanSdk)RedisProfilerEntryToSpanConverter.ProfilerCommandToSpan(this.tracer, null, profiledCommand.Object);
|
||||
Assert.Contains(result.Attributes, kvp => kvp.Key == "redis.flags");
|
||||
Assert.Equal("None, FireAndForget, NoRedirect", result.Attributes.GetValue("redis.flags"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
using StackExchange.Redis.Profiling;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Instrumentation.StackExchangeRedis
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="SpanContextShimTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="Defaults.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Trace;
|
||||
using Moq;
|
||||
using OpenTelemetry.Trace;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||
|
|
@ -49,8 +48,11 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
// build
|
||||
shim.Start();
|
||||
|
||||
tracerMock.Verify(o => o.StartRootSpan("foo", 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartRootSpan(
|
||||
"foo",
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -63,8 +65,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
shim.WithStartTimestamp(startTimestamp);
|
||||
|
||||
shim.Start();
|
||||
tracerMock.Verify(o => o.StartSpan("foo", It.IsAny<TelemetrySpan>(), 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == startTimestamp && !so.Links.Any())), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
It.IsAny<TelemetrySpan>(),
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == startTimestamp && !so.Links.Any())), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -79,8 +85,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
// build
|
||||
shim.Start();
|
||||
|
||||
tracerMock.Verify(o => o.StartSpan("foo", It.IsAny<TelemetrySpan>(), 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
It.IsAny<TelemetrySpan>(),
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -96,8 +106,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
// build
|
||||
shim.Start();
|
||||
|
||||
tracerMock.Verify(o => o.StartSpan("foo", span.Span, 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
span.Span,
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -121,8 +135,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
tracerMock = GetDefaultTracerMock();
|
||||
shim = new SpanBuilderShim(tracerMock.Object, "foo", new List<string> { "bar" });
|
||||
shim.Start();
|
||||
tracerMock.Verify(o => o.StartSpan("foo", It.IsAny<TelemetrySpan>(), 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
It.IsAny<TelemetrySpan>(),
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -145,8 +163,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
// build
|
||||
shim.Start();
|
||||
|
||||
tracerMock.Verify(o => o.StartSpan("foo", span1.Span, 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && so.Links.Single().Context.Equals(span2.Span.Context))), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
span1.Span,
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && so.Links.Single().Context.Equals(span2.Span.Context))), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -162,8 +184,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
shim.Start();
|
||||
|
||||
// should be no parent.
|
||||
tracerMock.Verify(o => o.StartSpan("foo", It.IsAny<TelemetrySpan>(), 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
It.IsAny<TelemetrySpan>(),
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -179,8 +205,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
// build
|
||||
shim.Start();
|
||||
|
||||
tracerMock.Verify(o => o.StartSpan("foo", spanContext.SpanContext, 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
spanContext.SpanContext,
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && !so.Links.Any())), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -198,8 +228,12 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
// build
|
||||
shim.Start();
|
||||
|
||||
tracerMock.Verify(o => o.StartSpan("foo", spanContext1.SpanContext, 0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && so.Links.Single().Context.Equals(spanContext2.SpanContext))), Times.Once);
|
||||
tracerMock.Verify(
|
||||
o => o.StartSpan(
|
||||
"foo",
|
||||
spanContext1.SpanContext,
|
||||
0,
|
||||
It.Is<SpanCreationOptions>(so => so.StartTimestamp == default && so.Links.Single().Context.Equals(spanContext2.SpanContext))), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
// </copyright>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
namespace OpenTelemetry.Shims.OpenTracing.Tests
|
||||
|
|
|
|||
|
|
@ -174,9 +174,6 @@ namespace OpenTelemetry.Shims.OpenTracing.Tests
|
|||
// TODO BaggageItems are not implemented yet.
|
||||
}
|
||||
|
||||
public interface UnsupportedCarrierType
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Simple ITextMap implementation used for the inject/extract tests.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="CounterCleanUpTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="MeterFactoryTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
|
|||
|
|
@ -15,26 +15,25 @@
|
|||
// </copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Context.Test
|
||||
{
|
||||
public class CorrelationContextBuilderTest
|
||||
{
|
||||
private const string KEY_1 = "key 1";
|
||||
private const string KEY_2 = "key 2";
|
||||
private const string Key1 = "key 1";
|
||||
private const string Key2 = "key 2";
|
||||
|
||||
private const string VALUE_1 = "value 1";
|
||||
private const string VALUE_2 = "value 2";
|
||||
private const string Value1 = "value 1";
|
||||
private const string Value2 = "value 2";
|
||||
|
||||
private static readonly List<CorrelationContextEntry> List1 = new List<CorrelationContextEntry>(1)
|
||||
{new CorrelationContextEntry(KEY_1, VALUE_1)};
|
||||
{ new CorrelationContextEntry(Key1, Value1) };
|
||||
|
||||
private static readonly List<CorrelationContextEntry> List2 = new List<CorrelationContextEntry>(2)
|
||||
{
|
||||
new CorrelationContextEntry(KEY_1, VALUE_1),
|
||||
new CorrelationContextEntry(KEY_2, VALUE_2),
|
||||
new CorrelationContextEntry(Key1, Value1),
|
||||
new CorrelationContextEntry(Key2, Value2),
|
||||
};
|
||||
|
||||
public CorrelationContextBuilderTest()
|
||||
|
|
@ -51,7 +50,7 @@ namespace OpenTelemetry.Context.Test
|
|||
dc = CorrelationContextBuilder.CreateContext(CorrelationContext.Empty.Entries);
|
||||
Assert.Equal(CorrelationContext.Empty, dc);
|
||||
|
||||
dc = CorrelationContextBuilder.CreateContext(KEY_1, VALUE_1);
|
||||
dc = CorrelationContextBuilder.CreateContext(Key1, Value1);
|
||||
Assert.Equal(CorrelationContextBuilder.CreateContext(List1), dc);
|
||||
|
||||
Assert.Equal(dc, new CorrelationContextBuilder(dc).Build());
|
||||
|
|
@ -64,41 +63,35 @@ namespace OpenTelemetry.Context.Test
|
|||
|
||||
Assert.Equal(
|
||||
CorrelationContextBuilder.CreateContext(List1), new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(KEY_1, VALUE_1)
|
||||
.Build()
|
||||
);
|
||||
.Add(Key1, Value1)
|
||||
.Build());
|
||||
|
||||
Assert.Equal(
|
||||
CorrelationContextBuilder.CreateContext(List1), new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(new CorrelationContextEntry(KEY_1, VALUE_1))
|
||||
.Build()
|
||||
);
|
||||
.Add(new CorrelationContextEntry(Key1, Value1))
|
||||
.Build());
|
||||
|
||||
Assert.Equal(
|
||||
CorrelationContextBuilder.CreateContext(List2), new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(KEY_1, VALUE_1)
|
||||
.Add(KEY_2, VALUE_2)
|
||||
.Build()
|
||||
);
|
||||
.Add(Key1, Value1)
|
||||
.Add(Key2, Value2)
|
||||
.Build());
|
||||
|
||||
Assert.Equal(
|
||||
CorrelationContextBuilder.CreateContext(List2), new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(new CorrelationContextEntry(KEY_1, VALUE_1))
|
||||
.Add(new CorrelationContextEntry(KEY_2, VALUE_2))
|
||||
.Build()
|
||||
);
|
||||
.Add(new CorrelationContextEntry(Key1, Value1))
|
||||
.Add(new CorrelationContextEntry(Key2, Value2))
|
||||
.Build());
|
||||
|
||||
Assert.Equal(
|
||||
CorrelationContextBuilder.CreateContext(List1), new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List1)
|
||||
.Build()
|
||||
);
|
||||
.Build());
|
||||
|
||||
Assert.Equal(
|
||||
CorrelationContextBuilder.CreateContext(List2), new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List2)
|
||||
.Build()
|
||||
);
|
||||
.Build());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -107,17 +100,15 @@ namespace OpenTelemetry.Context.Test
|
|||
Assert.Equal(
|
||||
CorrelationContextBuilder.CreateContext(List1), new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List2)
|
||||
.Remove(KEY_2)
|
||||
.Build()
|
||||
);
|
||||
.Remove(Key2)
|
||||
.Build());
|
||||
|
||||
Assert.Equal(
|
||||
CorrelationContext.Empty, new CorrelationContextBuilder(inheritCurrentContext: false)
|
||||
.Add(List2)
|
||||
.Remove(KEY_2)
|
||||
.Remove(KEY_1)
|
||||
.Build()
|
||||
);
|
||||
.Remove(Key2)
|
||||
.Remove(Key1)
|
||||
.Build());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenTelemetry.Context.Test
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -51,7 +50,7 @@ namespace OpenTelemetry.Context.Test
|
|||
[Fact]
|
||||
public void AddExtraKey()
|
||||
{
|
||||
var list = new List<CorrelationContextEntry>(1) { new CorrelationContextEntry(K1, V1)};
|
||||
var list = new List<CorrelationContextEntry>(1) { new CorrelationContextEntry(K1, V1) };
|
||||
var dc = CorrelationContextBuilder.CreateContext(list);
|
||||
Assert.Equal(list, dc.Entries);
|
||||
|
||||
|
|
@ -104,7 +103,7 @@ namespace OpenTelemetry.Context.Test
|
|||
Assert.True(i.MoveNext());
|
||||
var tag2 = i.Current;
|
||||
Assert.False(i.MoveNext());
|
||||
Assert.Equal(new List<CorrelationContextEntry> { new CorrelationContextEntry(K1, V1), new CorrelationContextEntry(K2, V2)}, new List<CorrelationContextEntry> { tag1, tag2 });
|
||||
Assert.Equal(new List<CorrelationContextEntry> { new CorrelationContextEntry(K1, V1), new CorrelationContextEntry(K2, V2) }, new List<CorrelationContextEntry> { tag1, tag2 });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ namespace OpenTelemetry.Context.Test
|
|||
{
|
||||
public class DistributedContextsScopeTest
|
||||
{
|
||||
private const string KEY_1 = "key 1";
|
||||
private const string KEY_2 = "key 2";
|
||||
private const string Key1 = "key 1";
|
||||
private const string Key2 = "key 2";
|
||||
|
||||
private const string VALUE_1 = "value 1";
|
||||
private const string VALUE_2 = "value 2";
|
||||
private const string Value1 = "value 1";
|
||||
private const string Value2 = "value 2";
|
||||
|
||||
[Fact]
|
||||
public void NoopContextCarrier()
|
||||
|
|
@ -33,11 +33,11 @@ namespace OpenTelemetry.Context.Test
|
|||
DistributedContext.Carrier = NoopDistributedContextCarrier.Instance;
|
||||
List<CorrelationContextEntry> list = new List<CorrelationContextEntry>(2)
|
||||
{
|
||||
new CorrelationContextEntry(KEY_1, VALUE_1), new CorrelationContextEntry(KEY_2, VALUE_2),
|
||||
new CorrelationContextEntry(Key1, Value1), new CorrelationContextEntry(Key2, Value2),
|
||||
};
|
||||
Assert.Equal(DistributedContext.Empty, DistributedContext.Current);
|
||||
|
||||
using (DistributedContext.SetCurrent(DistributedContextBuilder.CreateContext(KEY_1, VALUE_1)))
|
||||
using (DistributedContext.SetCurrent(DistributedContextBuilder.CreateContext(Key1, Value1)))
|
||||
{
|
||||
Assert.Equal(DistributedContext.Empty, DistributedContext.Current);
|
||||
using (DistributedContext.SetCurrent(DistributedContextBuilder.CreateContext(list)))
|
||||
|
|
@ -53,9 +53,9 @@ namespace OpenTelemetry.Context.Test
|
|||
public async void AsyncContextCarrier()
|
||||
{
|
||||
DistributedContext.Carrier = AsyncLocalDistributedContextCarrier.Instance;
|
||||
List<CorrelationContextEntry> list = new List<CorrelationContextEntry>(2) { new CorrelationContextEntry(KEY_1, VALUE_1), new CorrelationContextEntry(KEY_2, VALUE_2), };
|
||||
List<CorrelationContextEntry> list = new List<CorrelationContextEntry>(2) { new CorrelationContextEntry(Key1, Value1), new CorrelationContextEntry(Key2, Value2), };
|
||||
|
||||
var dc1 = DistributedContextBuilder.CreateContext(KEY_1, VALUE_1);
|
||||
var dc1 = DistributedContextBuilder.CreateContext(Key1, Value1);
|
||||
var dc2 = DistributedContextBuilder.CreateContext(list);
|
||||
|
||||
DistributedContext.SetCurrent(DistributedContext.Empty);
|
||||
|
|
@ -75,8 +75,10 @@ namespace OpenTelemetry.Context.Test
|
|||
{
|
||||
await Task.Run(() => Assert.Equal(dc2, DistributedContext.Current));
|
||||
}
|
||||
|
||||
await Task.Run(() => Assert.Equal(dc1, DistributedContext.Current));
|
||||
}
|
||||
|
||||
Assert.Equal(DistributedContext.Empty, DistributedContext.Current);
|
||||
await Task.Run(() => Assert.Equal(DistributedContext.Empty, DistributedContext.Current));
|
||||
}
|
||||
|
|
@ -85,8 +87,8 @@ namespace OpenTelemetry.Context.Test
|
|||
public async void TestContextInheritance()
|
||||
{
|
||||
DistributedContext.Carrier = AsyncLocalDistributedContextCarrier.Instance;
|
||||
var list1 = new List<CorrelationContextEntry>(1) { new CorrelationContextEntry(KEY_1, VALUE_1) };
|
||||
var list2 = new List<CorrelationContextEntry>(2) { new CorrelationContextEntry(KEY_1, VALUE_1), new CorrelationContextEntry(KEY_2, VALUE_2) };
|
||||
var list1 = new List<CorrelationContextEntry>(1) { new CorrelationContextEntry(Key1, Value1) };
|
||||
var list2 = new List<CorrelationContextEntry>(2) { new CorrelationContextEntry(Key1, Value1), new CorrelationContextEntry(Key2, Value2) };
|
||||
|
||||
DistributedContext.SetCurrent(DistributedContext.Empty);
|
||||
await Task.Run(() => Assert.Equal(DistributedContext.Empty, DistributedContext.Current));
|
||||
|
|
@ -99,10 +101,10 @@ namespace OpenTelemetry.Context.Test
|
|||
{
|
||||
await Task.Run(() => Assert.Equal(DistributedContextBuilder.CreateContext(list1), DistributedContext.Current));
|
||||
|
||||
using (DistributedContext.SetCurrent(new DistributedContextBuilder(inheritCurrentContext: true).Correlations(b => b.Add(KEY_2, VALUE_2)).Build()))
|
||||
using (DistributedContext.SetCurrent(new DistributedContextBuilder(inheritCurrentContext: true).Correlations(b => b.Add(Key2, Value2)).Build()))
|
||||
{
|
||||
await Task.Run(() => Assert.Equal(DistributedContextBuilder.CreateContext(list2), DistributedContext.Current));
|
||||
using (DistributedContext.SetCurrent(new DistributedContextBuilder(inheritCurrentContext: true).Correlations(b => b.Remove(KEY_2)).Build()))
|
||||
using (DistributedContext.SetCurrent(new DistributedContextBuilder(inheritCurrentContext: true).Correlations(b => b.Remove(Key2)).Build()))
|
||||
{
|
||||
await Task.Run(() => Assert.Equal(DistributedContextBuilder.CreateContext(list1), DistributedContext.Current));
|
||||
}
|
||||
|
|
@ -121,4 +123,3 @@ namespace OpenTelemetry.Context.Test
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
|
@ -30,7 +29,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
public DistributedContextDeserializationTest()
|
||||
{
|
||||
DistributedContext.Carrier = AsyncLocalDistributedContextCarrier.Instance;
|
||||
serializer = new DistributedContextBinarySerializer();
|
||||
this.serializer = new DistributedContextBinarySerializer();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -45,17 +44,17 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
[Fact]
|
||||
public void TestNoTagsSerialization()
|
||||
{
|
||||
var dc = serializer.FromByteArray(serializer.ToByteArray(DistributedContext.Empty));
|
||||
var dc = this.serializer.FromByteArray(this.serializer.ToByteArray(DistributedContext.Empty));
|
||||
Assert.Empty(dc.CorrelationContext.Entries);
|
||||
|
||||
dc = serializer.FromByteArray(new byte[] { SerializationUtils.VersionId }); // One byte that represents Version ID.
|
||||
dc = this.serializer.FromByteArray(new byte[] { SerializationUtils.VersionId }); // One byte that represents Version ID.
|
||||
Assert.Empty(dc.CorrelationContext.Entries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDeserializeEmptyByteArrayThrowException()
|
||||
{
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[0]));
|
||||
Assert.Equal(DistributedContext.Empty, this.serializer.FromByteArray(new byte[0]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -64,7 +63,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
var output = new MemoryStream();
|
||||
output.WriteByte(SerializationUtils.VersionId);
|
||||
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
|
||||
for (var i = 0; i < (SerializationUtils.TagContextSerializedSizeLimit / 8) - 1; i++)
|
||||
{
|
||||
// Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
|
||||
string str = i.ToString("0000");
|
||||
|
|
@ -76,7 +75,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("last", "last1", output);
|
||||
|
||||
var bytes = output.ToArray();
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(bytes));
|
||||
Assert.Equal(DistributedContext.Empty, this.serializer.FromByteArray(bytes));
|
||||
}
|
||||
|
||||
// Deserializing this inPut should cause an error, even though it represents a relatively small
|
||||
|
|
@ -87,7 +86,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
var output = new MemoryStream();
|
||||
output.WriteByte(SerializationUtils.VersionId);
|
||||
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
|
||||
for (var i = 0; i < (SerializationUtils.TagContextSerializedSizeLimit / 8) - 1; i++)
|
||||
{
|
||||
// Each tag will be with format {key : "key_", value : "0123"}, so the length of it is 8.
|
||||
EncodeTagToOutPut("key_", i.ToString("0000"), output);
|
||||
|
|
@ -98,7 +97,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("key_", "last1", output);
|
||||
|
||||
var bytes = output.ToArray();
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(bytes));
|
||||
Assert.Equal(DistributedContext.Empty, this.serializer.FromByteArray(bytes));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -109,7 +108,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("Key", "Value", output);
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext("Key", "Value");
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
Assert.Equal(expected, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -121,9 +120,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("Key2", "Value2", output);
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext(
|
||||
new List<CorrelationContextEntry>(2) { new CorrelationContextEntry("Key1", "Value1"), new CorrelationContextEntry("Key2", "Value2") }
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
new List<CorrelationContextEntry>(2) { new CorrelationContextEntry("Key1", "Value1"), new CorrelationContextEntry("Key2", "Value2") });
|
||||
Assert.Equal(expected, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -135,7 +133,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("Key1", "Value2", output);
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext("Key1", "Value2");
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
Assert.Equal(expected, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -155,9 +153,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
new CorrelationContextEntry("Key1", "Value4"),
|
||||
new CorrelationContextEntry("Key2", "Value5"),
|
||||
new CorrelationContextEntry("Key3", "Value3"),
|
||||
}
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
});
|
||||
Assert.Equal(expected, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -169,7 +166,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
EncodeTagToOutPut("Key1", "Value2", output);
|
||||
|
||||
var expected = DistributedContextBuilder.CreateContext("Key1", "Value2");
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
Assert.Equal(expected, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -189,9 +186,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
new CorrelationContextEntry("Key1", "Value1"),
|
||||
new CorrelationContextEntry("Key2", "Value2"),
|
||||
new CorrelationContextEntry("Key3", "Value3"),
|
||||
}
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
});
|
||||
Assert.Equal(expected, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -213,9 +209,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
new CorrelationContextEntry("Key1", "Value1"),
|
||||
new CorrelationContextEntry("Key2", "Value2"),
|
||||
}
|
||||
);
|
||||
Assert.Equal(expected, serializer.FromByteArray(output.ToArray()));
|
||||
});
|
||||
Assert.Equal(expected, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -229,26 +224,26 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
output.Write(new byte[] { 1, 2, 3, 4 }, 0, 4);
|
||||
|
||||
EncodeTagToOutPut("Key", "Value", output);
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(output.ToArray()));
|
||||
Assert.Equal(DistributedContext.Empty, this.serializer.FromByteArray(output.ToArray()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDeserializeWrongFormat()
|
||||
{
|
||||
// encoded tags should follow the format <version_id>(<tag_field_id><tag_encoding>)*
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[3]));
|
||||
Assert.Equal(DistributedContext.Empty, this.serializer.FromByteArray(new byte[3]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDeserializeWrongVersionId()
|
||||
{
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[] { SerializationUtils.VersionId + 1 }));
|
||||
Assert.Equal(DistributedContext.Empty, this.serializer.FromByteArray(new byte[] { SerializationUtils.VersionId + 1 }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestDeserializeNegativeVersionId()
|
||||
{
|
||||
Assert.Equal(DistributedContext.Empty, serializer.FromByteArray(new byte[] { 0xff }));
|
||||
Assert.Equal(DistributedContext.Empty, this.serializer.FromByteArray(new byte[] { 0xff }));
|
||||
}
|
||||
|
||||
// <tag_encoding> ==
|
||||
|
|
@ -257,14 +252,14 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
// <tag_key> == tag_key_len bytes comprising tag key name
|
||||
// <tag_val_len> == varint encoded integer
|
||||
// <tag_val> == tag_val_len bytes comprising UTF-8 string
|
||||
private static void EncodeTagToOutPut(String key, String value, MemoryStream output)
|
||||
private static void EncodeTagToOutPut(string key, string value, MemoryStream output)
|
||||
{
|
||||
output.WriteByte(SerializationUtils.TagFieldId);
|
||||
EncodeString(key, output);
|
||||
EncodeString(value, output);
|
||||
}
|
||||
|
||||
private static void EncodeString(String input, MemoryStream output)
|
||||
private static void EncodeString(string input, MemoryStream output)
|
||||
{
|
||||
var length = input.Length;
|
||||
var bytes = new byte[VarInt.VarIntSize(length)];
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Context.Propagation.Test
|
||||
{
|
||||
|
|
@ -25,7 +25,6 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
private const string K2 = "k2";
|
||||
private const string K3 = "k3";
|
||||
|
||||
private const string V_EMPTY = "";
|
||||
private const string V1 = "v1";
|
||||
private const string V2 = "v2";
|
||||
private const string V3 = "v3";
|
||||
|
|
@ -50,11 +49,10 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
new CorrelationContextEntry(K1, V1),
|
||||
new CorrelationContextEntry(K2, V2),
|
||||
new CorrelationContextEntry(K3, V3),
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this.TestRoundtripSerialization(expected);
|
||||
this.TestRoundtripSerialization(DistributedContextBuilder.CreateContext(K1, V_EMPTY));
|
||||
this.TestRoundtripSerialization(DistributedContextBuilder.CreateContext(K1, string.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -47,25 +45,25 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
public DistributedContextSerializationTest()
|
||||
{
|
||||
DistributedContext.Carrier = AsyncLocalDistributedContextCarrier.Instance;
|
||||
serializer = new DistributedContextBinarySerializer();
|
||||
this.serializer = new DistributedContextBinarySerializer();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSerializeDefault()
|
||||
{
|
||||
TestSerialize();
|
||||
this.TestSerialize();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSerializeWithOneTag()
|
||||
{
|
||||
TestSerialize(T1);
|
||||
this.TestSerialize(T1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSerializeWithMultipleTags()
|
||||
{
|
||||
TestSerialize(T1, T2, T3, T4);
|
||||
this.TestSerialize(T1, T2, T3, T4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -73,7 +71,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var list = new List<CorrelationContextEntry>();
|
||||
|
||||
for (var i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
|
||||
for (var i = 0; i < (SerializationUtils.TagContextSerializedSizeLimit / 8) - 1; i++)
|
||||
{
|
||||
// Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
|
||||
var str = i.ToString("0000");
|
||||
|
|
@ -85,37 +83,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
list.Add(new CorrelationContextEntry("last", "last1"));
|
||||
|
||||
var dc = DistributedContextBuilder.CreateContext(list);
|
||||
Assert.Empty(serializer.ToByteArray(dc));
|
||||
}
|
||||
|
||||
private void TestSerialize(params CorrelationContextEntry[] tags)
|
||||
{
|
||||
var list = new List<CorrelationContextEntry>(tags);
|
||||
|
||||
var actual = serializer.ToByteArray(DistributedContextBuilder.CreateContext(list));
|
||||
var tagsList = tags.ToList();
|
||||
var tagPermutation = Permutate(tagsList, tagsList.Count);
|
||||
ISet<string> possibleOutPuts = new HashSet<string>();
|
||||
|
||||
foreach (var distributedContextEntries in tagPermutation)
|
||||
{
|
||||
var l = (List<CorrelationContextEntry>)distributedContextEntries;
|
||||
var expected = new MemoryStream();
|
||||
expected.WriteByte(SerializationUtils.VersionId);
|
||||
|
||||
foreach (var tag in l)
|
||||
{
|
||||
expected.WriteByte(SerializationUtils.TagFieldId);
|
||||
EncodeString(tag.Key, expected);
|
||||
EncodeString(tag.Value, expected);
|
||||
}
|
||||
|
||||
var bytes = expected.ToArray();
|
||||
possibleOutPuts.Add(Encoding.UTF8.GetString(bytes));
|
||||
}
|
||||
|
||||
var exp = Encoding.UTF8.GetString(actual);
|
||||
Assert.Contains(exp, possibleOutPuts);
|
||||
Assert.Empty(this.serializer.ToByteArray(dc));
|
||||
}
|
||||
|
||||
private static void EncodeString(string input, MemoryStream byteArrayOutPutStream)
|
||||
|
|
@ -151,5 +119,35 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TestSerialize(params CorrelationContextEntry[] tags)
|
||||
{
|
||||
var list = new List<CorrelationContextEntry>(tags);
|
||||
|
||||
var actual = this.serializer.ToByteArray(DistributedContextBuilder.CreateContext(list));
|
||||
var tagsList = tags.ToList();
|
||||
var tagPermutation = Permutate(tagsList, tagsList.Count);
|
||||
ISet<string> possibleOutPuts = new HashSet<string>();
|
||||
|
||||
foreach (var distributedContextEntries in tagPermutation)
|
||||
{
|
||||
var l = (List<CorrelationContextEntry>)distributedContextEntries;
|
||||
var expected = new MemoryStream();
|
||||
expected.WriteByte(SerializationUtils.VersionId);
|
||||
|
||||
foreach (var tag in l)
|
||||
{
|
||||
expected.WriteByte(SerializationUtils.TagFieldId);
|
||||
EncodeString(tag.Key, expected);
|
||||
EncodeString(tag.Value, expected);
|
||||
}
|
||||
|
||||
var bytes = expected.ToArray();
|
||||
possibleOutPuts.Add(Encoding.UTF8.GetString(bytes));
|
||||
}
|
||||
|
||||
var exp = Encoding.UTF8.GetString(actual);
|
||||
Assert.Contains(exp, possibleOutPuts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,31 @@ namespace OpenTelemetry.Internal.Test
|
|||
{
|
||||
private static readonly Random GlobalRandom = new Random();
|
||||
|
||||
public static IDisposable RunServer(Action<HttpListenerContext> action, out string host, out int port)
|
||||
{
|
||||
host = "localhost";
|
||||
port = 0;
|
||||
RunningServer server = null;
|
||||
|
||||
var retryCount = 5;
|
||||
while (retryCount > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
port = GlobalRandom.Next(2000, 5000);
|
||||
server = new RunningServer(action, host, port);
|
||||
server.Start();
|
||||
break;
|
||||
}
|
||||
catch (HttpListenerException)
|
||||
{
|
||||
retryCount--;
|
||||
}
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
private class RunningServer : IDisposable
|
||||
{
|
||||
private readonly Task httpListenerTask;
|
||||
|
|
@ -51,11 +76,14 @@ namespace OpenTelemetry.Internal.Test
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex is ObjectDisposedException // Listener was closed before we got into GetContextAsync.
|
||||
|| (ex is HttpListenerException httpEx && httpEx.ErrorCode == 995)) // Listener was closed while we were in GetContextAsync.
|
||||
if (ex is ObjectDisposedException
|
||||
|| (ex is HttpListenerException httpEx && httpEx.ErrorCode == 995))
|
||||
{
|
||||
// Listener was closed before we got into GetContextAsync or
|
||||
// Listener was closed while we were in GetContextAsync.
|
||||
break;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
@ -80,30 +108,5 @@ namespace OpenTelemetry.Internal.Test
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IDisposable RunServer(Action<HttpListenerContext> action, out string host, out int port)
|
||||
{
|
||||
host = "localhost";
|
||||
port = 0;
|
||||
RunningServer server = null;
|
||||
|
||||
var retryCount = 5;
|
||||
while (retryCount > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
port = GlobalRandom.Next(2000, 5000);
|
||||
server = new RunningServer(action, host, port);
|
||||
server.Start();
|
||||
break;
|
||||
}
|
||||
catch (HttpListenerException)
|
||||
{
|
||||
retryCount--;
|
||||
}
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Aggregators;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
|
@ -23,14 +22,6 @@ namespace OpenTelemetry.Metrics.Test
|
|||
{
|
||||
public class CounterAggregatorTest
|
||||
{
|
||||
private class UpdateThreadArguments<T> where T : struct
|
||||
{
|
||||
public ManualResetEvent mreToBlockUpdateThread;
|
||||
public ManualResetEvent mreToEnsureAllThreadsStart;
|
||||
public int threadsStartedCount;
|
||||
public Aggregator<T> counterSumAggregator;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CounterAggregatorAggregatesCorrectlyWhenMultipleThreadsUpdatesLong()
|
||||
{
|
||||
|
|
@ -48,10 +39,10 @@ namespace OpenTelemetry.Metrics.Test
|
|||
var argToThread =
|
||||
new UpdateThreadArguments<long>
|
||||
{
|
||||
counterSumAggregator = aggregator,
|
||||
threadsStartedCount = 0,
|
||||
mreToBlockUpdateThread = mre,
|
||||
mreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart,
|
||||
CounterSumAggregator = aggregator,
|
||||
ThreadsStartedCount = 0,
|
||||
MreToBlockUpdateThread = mre,
|
||||
MreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart,
|
||||
};
|
||||
|
||||
Thread[] t = new Thread[10];
|
||||
|
|
@ -98,10 +89,10 @@ namespace OpenTelemetry.Metrics.Test
|
|||
var argToThread =
|
||||
new UpdateThreadArguments<double>
|
||||
{
|
||||
counterSumAggregator = aggregator,
|
||||
threadsStartedCount = 0,
|
||||
mreToBlockUpdateThread = mre,
|
||||
mreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart,
|
||||
CounterSumAggregator = aggregator,
|
||||
ThreadsStartedCount = 0,
|
||||
MreToBlockUpdateThread = mre,
|
||||
MreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart,
|
||||
};
|
||||
|
||||
Thread[] t = new Thread[10];
|
||||
|
|
@ -131,15 +122,14 @@ namespace OpenTelemetry.Metrics.Test
|
|||
Assert.Equal(105000000, sum.Sum);
|
||||
}
|
||||
|
||||
|
||||
private static void LongMetricUpdateThread(object obj)
|
||||
{
|
||||
var arguments = obj as UpdateThreadArguments<long>;
|
||||
var mre = arguments.mreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.mreToEnsureAllThreadsStart;
|
||||
var agg = arguments.counterSumAggregator;
|
||||
var mre = arguments.MreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.MreToEnsureAllThreadsStart;
|
||||
var agg = arguments.CounterSumAggregator;
|
||||
|
||||
if (Interlocked.Increment(ref arguments.threadsStartedCount) == 10)
|
||||
if (Interlocked.Increment(ref arguments.ThreadsStartedCount) == 10)
|
||||
{
|
||||
mreToEnsureAllThreadsStart.Set();
|
||||
}
|
||||
|
|
@ -156,11 +146,11 @@ namespace OpenTelemetry.Metrics.Test
|
|||
private static void DoubleMetricUpdateThread(object obj)
|
||||
{
|
||||
var arguments = obj as UpdateThreadArguments<double>;
|
||||
var mre = arguments.mreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.mreToEnsureAllThreadsStart;
|
||||
var agg = arguments.counterSumAggregator;
|
||||
var mre = arguments.MreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.MreToEnsureAllThreadsStart;
|
||||
var agg = arguments.CounterSumAggregator;
|
||||
|
||||
if (Interlocked.Increment(ref arguments.threadsStartedCount) == 10)
|
||||
if (Interlocked.Increment(ref arguments.ThreadsStartedCount) == 10)
|
||||
{
|
||||
mreToEnsureAllThreadsStart.Set();
|
||||
}
|
||||
|
|
@ -173,5 +163,14 @@ namespace OpenTelemetry.Metrics.Test
|
|||
agg.Update(10.5);
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateThreadArguments<T>
|
||||
where T : struct
|
||||
{
|
||||
public ManualResetEvent MreToBlockUpdateThread;
|
||||
public ManualResetEvent MreToEnsureAllThreadsStart;
|
||||
public int ThreadsStartedCount;
|
||||
public Aggregator<T> CounterSumAggregator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Aggregators;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using Xunit;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Aggregators;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
|
@ -23,14 +22,6 @@ namespace OpenTelemetry.Metrics.Test
|
|||
{
|
||||
public class MinMaxSumCountAggregatorTest
|
||||
{
|
||||
private class UpdateThreadArguments<T> where T : struct
|
||||
{
|
||||
public ManualResetEvent mreToBlockUpdateThread;
|
||||
public ManualResetEvent mreToEnsureAllThreadsStart;
|
||||
public int threadsStartedCount;
|
||||
public Aggregator<T> minMaxSumCountAggregator;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MeasureAggregatorAggregatesCorrectlyWhenMultipleThreadsUpdatesLong()
|
||||
{
|
||||
|
|
@ -47,10 +38,10 @@ namespace OpenTelemetry.Metrics.Test
|
|||
var mreToEnsureAllThreadsStart = new ManualResetEvent(false);
|
||||
|
||||
var argToThread = new UpdateThreadArguments<long>();
|
||||
argToThread.minMaxSumCountAggregator = aggregator;
|
||||
argToThread.threadsStartedCount = 0;
|
||||
argToThread.mreToBlockUpdateThread = mre;
|
||||
argToThread.mreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart;
|
||||
argToThread.MinMaxSumCountAggregator = aggregator;
|
||||
argToThread.ThreadsStartedCount = 0;
|
||||
argToThread.MreToBlockUpdateThread = mre;
|
||||
argToThread.MreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart;
|
||||
|
||||
Thread[] t = new Thread[10];
|
||||
for (int i = 0; i < 10; i++)
|
||||
|
|
@ -102,10 +93,10 @@ namespace OpenTelemetry.Metrics.Test
|
|||
var mreToEnsureAllThreadsStart = new ManualResetEvent(false);
|
||||
|
||||
var argToThread = new UpdateThreadArguments<double>();
|
||||
argToThread.minMaxSumCountAggregator = aggregator;
|
||||
argToThread.threadsStartedCount = 0;
|
||||
argToThread.mreToBlockUpdateThread = mre;
|
||||
argToThread.mreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart;
|
||||
argToThread.MinMaxSumCountAggregator = aggregator;
|
||||
argToThread.ThreadsStartedCount = 0;
|
||||
argToThread.MreToBlockUpdateThread = mre;
|
||||
argToThread.MreToEnsureAllThreadsStart = mreToEnsureAllThreadsStart;
|
||||
|
||||
Thread[] t = new Thread[10];
|
||||
for (int i = 0; i < 10; i++)
|
||||
|
|
@ -141,15 +132,14 @@ namespace OpenTelemetry.Metrics.Test
|
|||
Assert.Equal(100, summary.Max);
|
||||
}
|
||||
|
||||
|
||||
private static void LongMetricUpdateThread(object obj)
|
||||
{
|
||||
var arguments = obj as UpdateThreadArguments<long>;
|
||||
var mre = arguments.mreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.mreToEnsureAllThreadsStart;
|
||||
var agg = arguments.minMaxSumCountAggregator;
|
||||
var mre = arguments.MreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.MreToEnsureAllThreadsStart;
|
||||
var agg = arguments.MinMaxSumCountAggregator;
|
||||
|
||||
if (Interlocked.Increment(ref arguments.threadsStartedCount) == 10)
|
||||
if (Interlocked.Increment(ref arguments.ThreadsStartedCount) == 10)
|
||||
{
|
||||
mreToEnsureAllThreadsStart.Set();
|
||||
}
|
||||
|
|
@ -168,11 +158,11 @@ namespace OpenTelemetry.Metrics.Test
|
|||
private static void DoubleMetricUpdateThread(object obj)
|
||||
{
|
||||
var arguments = obj as UpdateThreadArguments<double>;
|
||||
var mre = arguments.mreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.mreToEnsureAllThreadsStart;
|
||||
var agg = arguments.minMaxSumCountAggregator;
|
||||
var mre = arguments.MreToBlockUpdateThread;
|
||||
var mreToEnsureAllThreadsStart = arguments.MreToEnsureAllThreadsStart;
|
||||
var agg = arguments.MinMaxSumCountAggregator;
|
||||
|
||||
if (Interlocked.Increment(ref arguments.threadsStartedCount) == 10)
|
||||
if (Interlocked.Increment(ref arguments.ThreadsStartedCount) == 10)
|
||||
{
|
||||
mreToEnsureAllThreadsStart.Set();
|
||||
}
|
||||
|
|
@ -187,5 +177,14 @@ namespace OpenTelemetry.Metrics.Test
|
|||
agg.Update(100.0);
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateThreadArguments<T>
|
||||
where T : struct
|
||||
{
|
||||
public ManualResetEvent MreToBlockUpdateThread;
|
||||
public ManualResetEvent MreToEnsureAllThreadsStart;
|
||||
public int ThreadsStartedCount;
|
||||
public Aggregator<T> MinMaxSumCountAggregator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Configuration;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using OpenTelemetry.Trace;
|
||||
using Xunit;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using System.Threading;
|
||||
using System;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace OpenTelemetry.Metrics.Test
|
||||
|
|
@ -59,16 +59,19 @@ namespace OpenTelemetry.Metrics.Test
|
|||
// ls2 is bound by user.
|
||||
testCounter.Add(context, 100, ls1);
|
||||
testCounter.Add(context, 10, ls1);
|
||||
|
||||
// initial status for temp bound instruments are UpdatePending.
|
||||
Assert.Equal(RecordStatus.UpdatePending, testCounter.GetAllBoundInstruments()[ls1].Status);
|
||||
|
||||
var boundCounterLabel2 = testCounter.Bind(ls2);
|
||||
boundCounterLabel2.Add(context, 200);
|
||||
|
||||
// initial/forever status for user bound instruments are Bound.
|
||||
Assert.Equal(RecordStatus.Bound, testCounter.GetAllBoundInstruments()[ls2].Status);
|
||||
|
||||
testCounter.Add(context, 200, ls3);
|
||||
testCounter.Add(context, 10, ls3);
|
||||
|
||||
// initial status for temp bound instruments are UpdatePending.
|
||||
Assert.Equal(RecordStatus.UpdatePending, testCounter.GetAllBoundInstruments()[ls3].Status);
|
||||
|
||||
|
|
@ -128,16 +131,19 @@ namespace OpenTelemetry.Metrics.Test
|
|||
// ls2 is bound by user.
|
||||
testCounter.Add(context, 100.0, ls1);
|
||||
testCounter.Add(context, 10.0, ls1);
|
||||
|
||||
// initial status for temp bound instruments are UpdatePending.
|
||||
Assert.Equal(RecordStatus.UpdatePending, testCounter.GetAllBoundInstruments()[ls1].Status);
|
||||
|
||||
var boundCounterLabel2 = testCounter.Bind(ls2);
|
||||
boundCounterLabel2.Add(context, 200.0);
|
||||
|
||||
// initial/forever status for user bound instruments are Bound.
|
||||
Assert.Equal(RecordStatus.Bound, testCounter.GetAllBoundInstruments()[ls2].Status);
|
||||
|
||||
testCounter.Add(context, 200.0, ls3);
|
||||
testCounter.Add(context, 10.0, ls3);
|
||||
|
||||
// initial status for temp bound instruments are UpdatePending.
|
||||
Assert.Equal(RecordStatus.UpdatePending, testCounter.GetAllBoundInstruments()[ls3].Status);
|
||||
|
||||
|
|
@ -202,12 +208,12 @@ namespace OpenTelemetry.Metrics.Test
|
|||
// candidate for removal after above step.
|
||||
var mre = new ManualResetEvent(false);
|
||||
var argsForMeterCollect = new ArgsToThread();
|
||||
argsForMeterCollect.mreToBlockStartOfThread = mre;
|
||||
argsForMeterCollect.callback = () => meter.Collect();
|
||||
argsForMeterCollect.MreToBlockStartOfThread = mre;
|
||||
argsForMeterCollect.Callback = () => meter.Collect();
|
||||
|
||||
var argsForCounterAdd = new ArgsToThread();
|
||||
argsForCounterAdd.mreToBlockStartOfThread = mre;
|
||||
argsForCounterAdd.callback = () => testCounter.Add(context, 100, ls1);
|
||||
argsForCounterAdd.MreToBlockStartOfThread = mre;
|
||||
argsForCounterAdd.Callback = () => testCounter.Add(context, 100, ls1);
|
||||
|
||||
var collectThread = new Thread(ThreadMethod);
|
||||
var updateThread = new Thread(ThreadMethod);
|
||||
|
|
@ -231,9 +237,9 @@ namespace OpenTelemetry.Metrics.Test
|
|||
meter.Collect();
|
||||
|
||||
long sum = 0;
|
||||
foreach (var exportedData in testProcessor.metrics)
|
||||
foreach (var exportedData in testProcessor.Metrics)
|
||||
{
|
||||
exportedData.Data.ForEach((data => sum += (data as Int64SumData).Sum));
|
||||
exportedData.Data.ForEach(data => sum += (data as Int64SumData).Sum);
|
||||
}
|
||||
|
||||
// 210 = 110 from initial update, 100 from the multi-thread test case.
|
||||
|
|
@ -271,12 +277,12 @@ namespace OpenTelemetry.Metrics.Test
|
|||
// candidate for removal after above step.
|
||||
var mre = new ManualResetEvent(false);
|
||||
var argsForMeterCollect = new ArgsToThread();
|
||||
argsForMeterCollect.mreToBlockStartOfThread = mre;
|
||||
argsForMeterCollect.callback = () => meter.Collect();
|
||||
argsForMeterCollect.MreToBlockStartOfThread = mre;
|
||||
argsForMeterCollect.Callback = () => meter.Collect();
|
||||
|
||||
var argsForCounterAdd = new ArgsToThread();
|
||||
argsForCounterAdd.mreToBlockStartOfThread = mre;
|
||||
argsForCounterAdd.callback = () => testCounter.Add(context, 100.0, ls1);
|
||||
argsForCounterAdd.MreToBlockStartOfThread = mre;
|
||||
argsForCounterAdd.Callback = () => testCounter.Add(context, 100.0, ls1);
|
||||
|
||||
var collectThread = new Thread(ThreadMethod);
|
||||
var updateThread = new Thread(ThreadMethod);
|
||||
|
|
@ -301,9 +307,9 @@ namespace OpenTelemetry.Metrics.Test
|
|||
|
||||
double sum = 0;
|
||||
|
||||
foreach (var exportedData in testProcessor.metrics)
|
||||
foreach (var exportedData in testProcessor.Metrics)
|
||||
{
|
||||
exportedData.Data.ForEach((data => sum += (data as DoubleSumData).Sum));
|
||||
exportedData.Data.ForEach(data => sum += (data as DoubleSumData).Sum);
|
||||
}
|
||||
|
||||
// 210 = 110 from initial update, 100 from the multi-thread test case.
|
||||
|
|
@ -313,18 +319,18 @@ namespace OpenTelemetry.Metrics.Test
|
|||
private static void ThreadMethod(object obj)
|
||||
{
|
||||
var args = obj as ArgsToThread;
|
||||
var mre = args.mreToBlockStartOfThread;
|
||||
var callBack = args.callback;
|
||||
var mre = args.MreToBlockStartOfThread;
|
||||
var callBack = args.Callback;
|
||||
|
||||
// Wait until signalled to call Collect.
|
||||
mre.WaitOne();
|
||||
callBack();
|
||||
}
|
||||
}
|
||||
|
||||
class ArgsToThread
|
||||
{
|
||||
public ManualResetEvent mreToBlockStartOfThread;
|
||||
public Action callback;
|
||||
private class ArgsToThread
|
||||
{
|
||||
public ManualResetEvent MreToBlockStartOfThread;
|
||||
public Action Callback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,6 @@
|
|||
// </copyright>
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Metrics;
|
||||
using OpenTelemetry.Metrics.Configuration;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Metrics.Test
|
||||
|
|
@ -63,6 +60,7 @@ namespace OpenTelemetry.Metrics.Test
|
|||
labels1.Add(new KeyValuePair<string, string>("dim1", "value1"));
|
||||
labels1.Add(new KeyValuePair<string, string>("dim2", "value2"));
|
||||
labels1.Add(new KeyValuePair<string, string>("dim3", "value3"));
|
||||
|
||||
// Construct labelset some labels.
|
||||
var labelSet1 = new LabelSetSdk(labels1);
|
||||
|
||||
|
|
@ -70,6 +68,7 @@ namespace OpenTelemetry.Metrics.Test
|
|||
labels1.Add(new KeyValuePair<string, string>("dim3", "value3"));
|
||||
labels1.Add(new KeyValuePair<string, string>("dim2", "value2"));
|
||||
labels1.Add(new KeyValuePair<string, string>("dim1", "value1"));
|
||||
|
||||
// Construct another labelset with same labels but in different order.
|
||||
var labelSet2 = new LabelSetSdk(labels1);
|
||||
|
||||
|
|
@ -82,7 +81,6 @@ namespace OpenTelemetry.Metrics.Test
|
|||
Assert.True(hashSet.Count == 1);
|
||||
Assert.Equal(labelSet1.GetHashCode(), labelSet2.GetHashCode());
|
||||
Assert.Equal(labelSet1, labelSet2);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace OpenTelemetry.Metrics.Config.Test
|
|||
public void MeterFactory_Default()
|
||||
{
|
||||
Assert.NotNull(MeterFactoryBase.Default);
|
||||
var defaultMeter = MeterFactoryBase.Default.GetMeter("");
|
||||
var defaultMeter = MeterFactoryBase.Default.GetMeter(string.Empty);
|
||||
Assert.NotNull(defaultMeter);
|
||||
Assert.Same(defaultMeter, MeterFactoryBase.Default.GetMeter("named meter"));
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ namespace OpenTelemetry.Metrics.Config.Test
|
|||
var factory = MeterFactory.Create(b => { });
|
||||
MeterFactoryBase.SetDefault(factory);
|
||||
|
||||
var defaultMeter = MeterFactoryBase.Default.GetMeter("");
|
||||
var defaultMeter = MeterFactoryBase.Default.GetMeter(string.Empty);
|
||||
Assert.NotNull(defaultMeter);
|
||||
Assert.IsType<MeterSdk>(defaultMeter);
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ namespace OpenTelemetry.Metrics.Config.Test
|
|||
[Fact]
|
||||
public void MeterFactory_UpdateDefault_CachedTracer()
|
||||
{
|
||||
var defaultMeter = MeterFactoryBase.Default.GetMeter("");
|
||||
var defaultMeter = MeterFactoryBase.Default.GetMeter(string.Empty);
|
||||
var noOpCounter = defaultMeter.CreateDoubleCounter("ctr");
|
||||
Assert.IsType<NoOpCounterMetric<double>>(noOpCounter);
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ namespace OpenTelemetry.Metrics.Config.Test
|
|||
var counter = defaultMeter.CreateDoubleCounter("ctr");
|
||||
Assert.IsType<DoubleCounterMetricSdk>(counter);
|
||||
|
||||
var newdefaultMeter = MeterFactoryBase.Default.GetMeter("");
|
||||
var newdefaultMeter = MeterFactoryBase.Default.GetMeter(string.Empty);
|
||||
Assert.NotSame(defaultMeter, newdefaultMeter);
|
||||
Assert.IsType<MeterSdk>(newdefaultMeter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Metrics.Configuration;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using OpenTelemetry.Trace;
|
||||
using Xunit;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
||||
namespace OpenTelemetry.Metrics.Test
|
||||
{
|
||||
|
|
@ -53,8 +53,8 @@ namespace OpenTelemetry.Metrics.Test
|
|||
|
||||
meter.Collect();
|
||||
|
||||
Assert.Single(testProcessor.metrics);
|
||||
var metric = testProcessor.metrics[0];
|
||||
Assert.Single(testProcessor.Metrics);
|
||||
var metric = testProcessor.Metrics[0];
|
||||
|
||||
Assert.Equal("testCounter", metric.MetricName);
|
||||
Assert.Equal("library1", metric.MetricNamespace);
|
||||
|
|
@ -96,8 +96,8 @@ namespace OpenTelemetry.Metrics.Test
|
|||
|
||||
meter.Collect();
|
||||
|
||||
Assert.Single(testProcessor.metrics);
|
||||
var metric = testProcessor.metrics[0];
|
||||
Assert.Single(testProcessor.Metrics);
|
||||
var metric = testProcessor.Metrics[0];
|
||||
Assert.Equal("testMeasure", metric.MetricName);
|
||||
Assert.Equal("library1", metric.MetricNamespace);
|
||||
|
||||
|
|
@ -124,12 +124,12 @@ namespace OpenTelemetry.Metrics.Test
|
|||
{
|
||||
var testProcessor = new TestMetricProcessor();
|
||||
var meter = MeterFactory.Create(mb => mb.SetMetricProcessor(testProcessor)).GetMeter("library1") as MeterSdk;
|
||||
var testObserver = meter.CreateInt64Observer("testObserver", TestCallbackLong);
|
||||
var testObserver = meter.CreateInt64Observer("testObserver", this.TestCallbackLong);
|
||||
|
||||
meter.Collect();
|
||||
|
||||
Assert.Single(testProcessor.metrics);
|
||||
var metric = testProcessor.metrics[0];
|
||||
Assert.Single(testProcessor.Metrics);
|
||||
var metric = testProcessor.Metrics[0];
|
||||
Assert.Equal("testObserver", metric.MetricName);
|
||||
Assert.Equal("library1", metric.MetricNamespace);
|
||||
|
||||
|
|
@ -150,12 +150,12 @@ namespace OpenTelemetry.Metrics.Test
|
|||
{
|
||||
var testProcessor = new TestMetricProcessor();
|
||||
var meter = MeterFactory.Create(mb => mb.SetMetricProcessor(testProcessor)).GetMeter("library1") as MeterSdk;
|
||||
var testObserver = meter.CreateDoubleObserver("testObserver", TestCallbackDouble);
|
||||
var testObserver = meter.CreateDoubleObserver("testObserver", this.TestCallbackDouble);
|
||||
|
||||
meter.Collect();
|
||||
|
||||
Assert.Single(testProcessor.metrics);
|
||||
var metric = testProcessor.metrics[0];
|
||||
Assert.Single(testProcessor.Metrics);
|
||||
var metric = testProcessor.Metrics[0];
|
||||
Assert.Equal("testObserver", metric.MetricName);
|
||||
Assert.Equal("library1", metric.MetricNamespace);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
using Xunit;
|
||||
using static OpenTelemetry.Metrics.Configuration.MeterFactory;
|
||||
|
||||
namespace OpenTelemetry.Metrics.Test
|
||||
|
|
@ -44,20 +44,21 @@ namespace OpenTelemetry.Metrics.Test
|
|||
int meter2CollectCount = 0;
|
||||
var meters = new Dictionary<MeterRegistryKey, MeterSdk>();
|
||||
var testMeter1 = new TestMeter("meter1", testProcessor, () => meter1CollectCount++);
|
||||
meters.Add(new MeterRegistryKey("meter1", ""), testMeter1);
|
||||
meters.Add(new MeterRegistryKey("meter1", string.Empty), testMeter1);
|
||||
var testMeter2 = new TestMeter("meter2", testProcessor, () => meter2CollectCount++);
|
||||
meters.Add(new MeterRegistryKey("meter2", ""), testMeter2);
|
||||
meters.Add(new MeterRegistryKey("meter2", string.Empty), testMeter2);
|
||||
|
||||
var pushInterval = TimeSpan.FromMilliseconds(controllerPushIntervalInMsec);
|
||||
var pushController = new PushMetricController(meters,
|
||||
var pushController = new PushMetricController(
|
||||
meters,
|
||||
testProcessor,
|
||||
testExporter,
|
||||
pushInterval,
|
||||
new CancellationTokenSource());
|
||||
|
||||
// Validate that collect is called on Meter1, Meter2.
|
||||
ValidateMeterCollect(ref meter1CollectCount, collectionCountExpectedMin, "meter1", TimeSpan.FromMilliseconds(maxWaitInMsec));
|
||||
ValidateMeterCollect(ref meter2CollectCount, collectionCountExpectedMin, "meter2", TimeSpan.FromMilliseconds(maxWaitInMsec));
|
||||
this.ValidateMeterCollect(ref meter1CollectCount, collectionCountExpectedMin, "meter1", TimeSpan.FromMilliseconds(maxWaitInMsec));
|
||||
this.ValidateMeterCollect(ref meter2CollectCount, collectionCountExpectedMin, "meter2", TimeSpan.FromMilliseconds(maxWaitInMsec));
|
||||
|
||||
// Export must be called same no: of times as Collect.
|
||||
Assert.True(exportCalledCount >= collectionCountExpectedMin);
|
||||
|
|
@ -72,7 +73,8 @@ namespace OpenTelemetry.Metrics.Test
|
|||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
Assert.True(meterCollectCount >= expectedMeterCollectCount
|
||||
Assert.True(
|
||||
meterCollectCount >= expectedMeterCollectCount
|
||||
&& meterCollectCount <= expectedMeterCollectCount,
|
||||
$"Actual Collect Count for meter: {meterName} is {meterCollectCount} vs Expected count of {expectedMeterCollectCount}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,19 +15,13 @@
|
|||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Metrics.Aggregators;
|
||||
using OpenTelemetry.Metrics.Export;
|
||||
|
||||
namespace OpenTelemetry.Metrics.Test
|
||||
{
|
||||
internal class TestMeter : MeterSdk
|
||||
{
|
||||
Action collectAction;
|
||||
private readonly Action collectAction;
|
||||
|
||||
internal TestMeter(string meterName, MetricProcessor metricProcessor, Action collectAction)
|
||||
: base(meterName, metricProcessor)
|
||||
|
|
|
|||
|
|
@ -21,17 +21,17 @@ namespace OpenTelemetry.Metrics.Test
|
|||
{
|
||||
internal class TestMetricProcessor : MetricProcessor
|
||||
{
|
||||
public List<Metric> metrics = new List<Metric>();
|
||||
public List<Metric> Metrics = new List<Metric>();
|
||||
|
||||
public override void FinishCollectionCycle(out IEnumerable<Metric> metrics)
|
||||
{
|
||||
metrics = this.metrics;
|
||||
this.metrics = new List<Metric>();
|
||||
metrics = this.Metrics;
|
||||
this.Metrics = new List<Metric>();
|
||||
}
|
||||
|
||||
public override void Process(Metric metric)
|
||||
{
|
||||
this.metrics.Add(metric);
|
||||
this.Metrics.Add(metric);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
using Xunit;
|
||||
using OpenTelemetry.Resources;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Resources;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Impl.Resources
|
||||
{
|
||||
|
|
@ -150,8 +150,8 @@ namespace OpenTelemetry.Impl.Resources
|
|||
{
|
||||
var attributes = new Dictionary<string, object>
|
||||
{
|
||||
{ "dynamic", new {} },
|
||||
{ "array", new int [1]},
|
||||
{ "dynamic", new { } },
|
||||
{ "array", new int[1] },
|
||||
{ "complex", this },
|
||||
{ "float", 0.1f },
|
||||
};
|
||||
|
|
@ -337,19 +337,13 @@ namespace OpenTelemetry.Impl.Resources
|
|||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, object> CreateAttributes(int attributeCount, int startIndex = 0)
|
||||
{
|
||||
var attributes = new Dictionary<string, object>();
|
||||
AddAttributes(attributes, attributeCount, startIndex);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static void ValidateAttributes(IEnumerable<KeyValuePair<string, object>> attributes, int startIndex = 0)
|
||||
{
|
||||
var keyValuePairs = attributes as KeyValuePair<string, object>[] ?? attributes.ToArray();
|
||||
for (var i = startIndex; i < keyValuePairs.Length; ++i)
|
||||
{
|
||||
Assert.Contains(new KeyValuePair<string, object>(
|
||||
Assert.Contains(
|
||||
new KeyValuePair<string, object>(
|
||||
$"{KeyName}{i}", $"{ValueName}{i}"), keyValuePairs);
|
||||
}
|
||||
}
|
||||
|
|
@ -368,5 +362,12 @@ namespace OpenTelemetry.Impl.Resources
|
|||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[Random.Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
private Dictionary<string, object> CreateAttributes(int attributeCount, int startIndex = 0)
|
||||
{
|
||||
var attributes = new Dictionary<string, object>();
|
||||
AddAttributes(attributes, attributeCount, startIndex);
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,10 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Export;
|
||||
|
||||
namespace OpenTelemetry.Testing.Export
|
||||
|
|
@ -27,12 +26,13 @@ namespace OpenTelemetry.Testing.Export
|
|||
{
|
||||
private readonly ConcurrentQueue<SpanData> spanDataList = new ConcurrentQueue<SpanData>();
|
||||
private readonly Action<IEnumerable<SpanData>> onExport;
|
||||
|
||||
public TestExporter(Action<IEnumerable<SpanData>> onExport)
|
||||
{
|
||||
this.onExport = onExport;
|
||||
}
|
||||
|
||||
public SpanData[] ExportedSpans => spanDataList.ToArray();
|
||||
public SpanData[] ExportedSpans => this.spanDataList.ToArray();
|
||||
|
||||
public bool WasShutDown { get; private set; } = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="ActivityListenerSdkTest.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="ActivityListenerSdkTest.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -32,9 +32,9 @@ namespace OpenTelemetry.Tests.Implementation.Trace
|
|||
[Fact]
|
||||
public void BuildSamplingParametersHandlesCurrentActivity()
|
||||
{
|
||||
using var activitySource = new ActivitySource(nameof(BuildSamplingParametersHandlesCurrentActivity));
|
||||
using var activitySource = new ActivitySource(nameof(this.BuildSamplingParametersHandlesCurrentActivity));
|
||||
|
||||
var latestSamplingParameters = new ActivitySamplingParameters();
|
||||
var latestSamplingParameters = default(ActivitySamplingParameters);
|
||||
|
||||
using var listener = new ActivityListener
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ namespace OpenTelemetry.Tests
|
|||
return attributes.FirstOrDefault(kvp => kvp.Key == key).Value;
|
||||
}
|
||||
|
||||
public static void AssertAreSame(this IEnumerable<KeyValuePair<string, object>> attributes,
|
||||
public static void AssertAreSame(
|
||||
this IEnumerable<KeyValuePair<string, object>> attributes,
|
||||
IEnumerable<KeyValuePair<string, object>> expectedAttributes)
|
||||
{
|
||||
var expectedKeyValuePairs = expectedAttributes as KeyValuePair<string, object>[] ?? expectedAttributes.ToArray();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -34,6 +33,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
multipleAttributes.Add("MyBooleanAttributeKey", true);
|
||||
multipleAttributes.Add("MyLongAttributeKey", 123);
|
||||
multipleAttributes.Add("MyDoubleAttributeKey", 0.005);
|
||||
|
||||
// Tests only that all the methods are not crashing/throwing errors.
|
||||
BlankSpan.Instance.SetAttribute(
|
||||
"MyStringAttributeKey2", "MyStringAttributeValue2");
|
||||
|
|
@ -62,7 +62,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void BadArguments_DoesNotThrow()
|
||||
{
|
||||
BlankSpan.Instance.Status = new Status();
|
||||
BlankSpan.Instance.Status = default(Status);
|
||||
BlankSpan.Instance.UpdateName(null);
|
||||
BlankSpan.Instance.SetAttribute(null, string.Empty);
|
||||
BlankSpan.Instance.SetAttribute(string.Empty, null);
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
bool start2Called = false;
|
||||
bool end1Called = false;
|
||||
bool end2Called = false;
|
||||
var processor1 = new TestProcessor(ss =>
|
||||
var processor1 = new TestProcessor(
|
||||
ss =>
|
||||
{
|
||||
start1Called = true;
|
||||
Assert.False(start2Called);
|
||||
|
|
@ -54,7 +55,8 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
Assert.True(start2Called);
|
||||
Assert.False(end2Called);
|
||||
});
|
||||
var processor2 = new TestProcessor(ss =>
|
||||
var processor2 = new TestProcessor(
|
||||
ss =>
|
||||
{
|
||||
start2Called = true;
|
||||
Assert.True(start1Called);
|
||||
|
|
@ -66,7 +68,6 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
Assert.True(start1Called);
|
||||
Assert.True(start2Called);
|
||||
Assert.True(end1Called);
|
||||
|
||||
});
|
||||
|
||||
var broadcastProcessor = new BroadcastProcessor(new[] { processor1, processor2 });
|
||||
|
|
@ -91,7 +92,8 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
bool start2Called = false;
|
||||
bool end1Called = false;
|
||||
bool end2Called = false;
|
||||
var processor1 = new TestProcessor(ss =>
|
||||
var processor1 = new TestProcessor(
|
||||
ss =>
|
||||
{
|
||||
start1Called = true;
|
||||
Assert.False(start2Called);
|
||||
|
|
@ -108,7 +110,8 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
throw new Exception("End exception");
|
||||
});
|
||||
|
||||
var processor2 = new TestProcessor(ss =>
|
||||
var processor2 = new TestProcessor(
|
||||
ss =>
|
||||
{
|
||||
start2Called = true;
|
||||
Assert.True(start1Called);
|
||||
|
|
@ -120,7 +123,6 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
Assert.True(start1Called);
|
||||
Assert.True(start2Called);
|
||||
Assert.True(end1Called);
|
||||
|
||||
});
|
||||
|
||||
var broadcastProcessor = new BroadcastProcessor(new[] { processor1, processor2 });
|
||||
|
|
@ -159,8 +161,6 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
{
|
||||
private readonly Action<SpanData> onStart;
|
||||
private readonly Action<SpanData> onEnd;
|
||||
public bool ShutdownCalled { get; private set; } = false;
|
||||
public bool DisposedCalled { get; private set; } = false;
|
||||
|
||||
public TestProcessor(Action<SpanData> onStart, Action<SpanData> onEnd)
|
||||
{
|
||||
|
|
@ -168,6 +168,10 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
this.onEnd = onEnd;
|
||||
}
|
||||
|
||||
public bool ShutdownCalled { get; private set; } = false;
|
||||
|
||||
public bool DisposedCalled { get; private set; } = false;
|
||||
|
||||
public override void OnStart(SpanData span)
|
||||
{
|
||||
this.onStart?.Invoke(span);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="TraceParamsTest.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="TraceConfigTest.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -43,9 +43,8 @@ namespace OpenTelemetry.Trace.Config.Test
|
|||
Assert.Throws<ArgumentOutOfRangeException>(() => new TracerConfiguration(1, 0, 1));
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void updateTraceParams_NonPositiveMaxNumberOfLinks()
|
||||
public void UpdateTraceParams_NonPositiveMaxNumberOfLinks()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new TracerConfiguration(1, 1, 0));
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Testing.Export;
|
||||
using OpenTelemetry.Trace;
|
||||
|
|
@ -102,6 +101,7 @@ namespace OpenTelemetry.Tests.Impl.Trace
|
|||
private class TestInstrumentation
|
||||
{
|
||||
private readonly Tracer tracer;
|
||||
|
||||
public TestInstrumentation(Tracer tracer)
|
||||
{
|
||||
this.tracer = tracer;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
public void TraceFactory_Default()
|
||||
{
|
||||
Assert.NotNull(TracerFactoryBase.Default);
|
||||
var defaultTracer = TracerFactoryBase.Default.GetTracer("");
|
||||
var defaultTracer = TracerFactoryBase.Default.GetTracer(string.Empty);
|
||||
Assert.NotNull(defaultTracer);
|
||||
Assert.Same(defaultTracer, TracerFactoryBase.Default.GetTracer("named tracerSdk"));
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
var factory = TracerFactory.Create(b => { });
|
||||
TracerFactoryBase.SetDefault(factory);
|
||||
|
||||
var defaultTracer = TracerFactoryBase.Default.GetTracer("");
|
||||
var defaultTracer = TracerFactoryBase.Default.GetTracer(string.Empty);
|
||||
Assert.NotNull(defaultTracer);
|
||||
Assert.IsType<TracerSdk>(defaultTracer);
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
[Fact]
|
||||
public void TraceFactory_UpdateDefault_CachedTracer()
|
||||
{
|
||||
var defaultTracer = TracerFactoryBase.Default.GetTracer("");
|
||||
var defaultTracer = TracerFactoryBase.Default.GetTracer(string.Empty);
|
||||
var noopSpan = defaultTracer.StartSpan("foo");
|
||||
Assert.IsType<BlankSpan>(noopSpan);
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ namespace OpenTelemetry.Tests.Impl.Trace.Config
|
|||
var span = defaultTracer.StartSpan("foo");
|
||||
Assert.IsType<SpanSdk>(span);
|
||||
|
||||
var newDefaultTracer = TracerFactoryBase.Default.GetTracer("");
|
||||
var newDefaultTracer = TracerFactoryBase.Default.GetTracer(string.Empty);
|
||||
Assert.NotSame(defaultTracer, newDefaultTracer);
|
||||
Assert.IsType<TracerSdk>(newDefaultTracer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Resources;
|
||||
using OpenTelemetry.Testing.Export;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
|
|
@ -40,7 +39,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
public void CreateFactory_DefaultBuilder()
|
||||
{
|
||||
var tracerFactory = TracerFactory.Create(b => { });
|
||||
var tracer = tracerFactory.GetTracer("");
|
||||
var tracer = tracerFactory.GetTracer(string.Empty);
|
||||
Assert.NotNull(tracer);
|
||||
Assert.IsType<TracerSdk>(tracer);
|
||||
|
||||
|
|
@ -120,7 +119,6 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.True(processor.IsDisposed);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void CreateFactory_BuilderWithMultiplePipelines()
|
||||
{
|
||||
|
|
@ -165,7 +163,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
public void GetTracer_NoName_NoVersion()
|
||||
{
|
||||
var tracerFactory = TracerFactory.Create(b => { });
|
||||
var tracer = (TracerSdk)tracerFactory.GetTracer("");
|
||||
var tracer = (TracerSdk)tracerFactory.GetTracer(string.Empty);
|
||||
Assert.DoesNotContain(tracer.LibraryResource.Attributes, kvp => kvp.Key == "name");
|
||||
Assert.DoesNotContain(tracer.LibraryResource.Attributes, kvp => kvp.Key == "version");
|
||||
}
|
||||
|
|
@ -228,7 +226,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
var tracer3 = tracerFactory.GetTracer("foo", "semver:2.3.4");
|
||||
var tracer4 = tracerFactory.GetTracer("bar", "semver:1.2.3");
|
||||
var tracer5 = tracerFactory.GetTracer("foo", "semver:1.2.3");
|
||||
var tracer6 = tracerFactory.GetTracer("");
|
||||
var tracer6 = tracerFactory.GetTracer(string.Empty);
|
||||
var tracer7 = tracerFactory.GetTracer(null);
|
||||
var tracer8 = tracerFactory.GetTracer(null, "semver:1.2.3");
|
||||
|
||||
|
|
@ -246,8 +244,6 @@ namespace OpenTelemetry.Trace.Test
|
|||
private readonly SpanExporter exporter;
|
||||
private readonly Action<SpanData> onEnd;
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public TestProcessor(Action<SpanData> onEnd)
|
||||
{
|
||||
this.exporter = null;
|
||||
|
|
@ -260,9 +256,11 @@ namespace OpenTelemetry.Trace.Test
|
|||
this.onEnd = null;
|
||||
}
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
IsDisposed = true;
|
||||
this.IsDisposed = true;
|
||||
}
|
||||
|
||||
public override void OnStart(SpanData span)
|
||||
|
|
@ -272,7 +270,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
public override void OnEnd(SpanData span)
|
||||
{
|
||||
this.onEnd?.Invoke(span);
|
||||
exporter?.ExportAsync(new[] { span }, default);
|
||||
this.exporter?.ExportAsync(new[] { span }, default);
|
||||
}
|
||||
|
||||
public override Task ShutdownAsync(CancellationToken cancellationToken)
|
||||
|
|
@ -284,13 +282,14 @@ namespace OpenTelemetry.Trace.Test
|
|||
private class TestInstrumentation : IDisposable
|
||||
{
|
||||
private readonly Tracer tracer;
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public TestInstrumentation(Tracer tracer)
|
||||
{
|
||||
this.tracer = tracer;
|
||||
}
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public SpanSdk Collect()
|
||||
{
|
||||
var span = this.tracer.StartSpan("foo");
|
||||
|
|
@ -300,7 +299,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
IsDisposed = true;
|
||||
this.IsDisposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="CurrentSpanTest.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="CurrentSpanTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -31,7 +31,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
|
||||
Activity.ForceDefaultIdFormat = true;
|
||||
|
||||
tracer = TracerFactory.Create(b => { }).GetTracer(null);
|
||||
this.tracer = TracerFactory.Create(b => { }).GetTracer(null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -55,7 +55,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
public void WithSpan_CloseDetaches(bool endSpan, bool recordEvents)
|
||||
{
|
||||
var spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), recordEvents ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None);
|
||||
var span = (SpanSdk)tracer.StartSpan("foo", spanContext);
|
||||
var span = (SpanSdk)this.tracer.StartSpan("foo", spanContext);
|
||||
|
||||
Assert.False(this.tracer.CurrentSpan.Context.IsValid);
|
||||
using (this.tracer.WithSpan(span, endSpan))
|
||||
|
|
@ -80,7 +80,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void WithSpan_NoFlag_DoesNotEndSpan()
|
||||
{
|
||||
var span = (SpanSdk)tracer.StartSpan("foo");
|
||||
var span = (SpanSdk)this.tracer.StartSpan("foo");
|
||||
|
||||
Assert.False(this.tracer.CurrentSpan.Context.IsValid);
|
||||
using (this.tracer.WithSpan(span))
|
||||
|
|
@ -99,7 +99,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void WithSpan_AttachAndDetach()
|
||||
{
|
||||
var span = (SpanSdk)tracer.StartSpan("foo");
|
||||
var span = (SpanSdk)this.tracer.StartSpan("foo");
|
||||
|
||||
Assert.False(this.tracer.CurrentSpan.Context.IsValid);
|
||||
using (this.tracer.WithSpan(span))
|
||||
|
|
@ -132,7 +132,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
public void WithSpan_EndDoesNotDetach(bool endSpan, bool recordEvents)
|
||||
{
|
||||
var spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), recordEvents ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None);
|
||||
var span = (SpanSdk)tracer.StartSpan("foo", spanContext);
|
||||
var span = (SpanSdk)this.tracer.StartSpan("foo", spanContext);
|
||||
|
||||
Assert.False(this.tracer.CurrentSpan.Context.IsValid);
|
||||
using (this.tracer.WithSpan(span, endSpan))
|
||||
|
|
@ -175,7 +175,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
activity.Start();
|
||||
|
||||
TelemetrySpan span;
|
||||
using (var scope = tracer.StartActiveSpanFromActivity("foo", activity, out span))
|
||||
using (var scope = this.tracer.StartActiveSpanFromActivity("foo", activity, out span))
|
||||
{
|
||||
Assert.IsType<SpanSdk>(scope);
|
||||
Assert.Same(scope, span);
|
||||
|
|
@ -194,7 +194,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
public void StartActiveSpan_OwningActivity()
|
||||
{
|
||||
SpanSdk span = null;
|
||||
using (var scope = tracer.StartActiveSpan("foo", out var ispan))
|
||||
using (var scope = this.tracer.StartActiveSpan("foo", out var ispan))
|
||||
{
|
||||
Assert.IsType<SpanSdk>(scope);
|
||||
span = (SpanSdk)scope;
|
||||
|
|
@ -213,7 +213,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void StartActiveSpan_WithSpan()
|
||||
{
|
||||
using (var scope = tracer.StartActiveSpan("foo", out var span))
|
||||
using (var scope = this.tracer.StartActiveSpan("foo", out var span))
|
||||
{
|
||||
Assert.Same(scope, this.tracer.WithSpan(span));
|
||||
}
|
||||
|
|
@ -229,10 +229,10 @@ namespace OpenTelemetry.Trace.Test
|
|||
{
|
||||
var spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), recordEvents ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None);
|
||||
|
||||
var parentSpan = tracer.StartSpan("parent", spanContext);
|
||||
var parentSpan = this.tracer.StartSpan("parent", spanContext);
|
||||
var parentScope = this.tracer.WithSpan(parentSpan);
|
||||
|
||||
var childSpan = (SpanSdk)tracer.StartSpan("child", parentSpan);
|
||||
var childSpan = (SpanSdk)this.tracer.StartSpan("child", parentSpan);
|
||||
var childActivity = childSpan.Activity;
|
||||
Assert.Same(parentSpan, this.tracer.CurrentSpan);
|
||||
|
||||
|
|
@ -243,7 +243,6 @@ namespace OpenTelemetry.Trace.Test
|
|||
Assert.Same(childSpan, this.tracer.CurrentSpan);
|
||||
Assert.Equal(childActivity, Activity.Current);
|
||||
|
||||
|
||||
// span not ended
|
||||
Assert.Equal(default, ((SpanSdk)parentSpan).EndTimestamp);
|
||||
}
|
||||
|
|
@ -257,11 +256,11 @@ namespace OpenTelemetry.Trace.Test
|
|||
{
|
||||
var spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), recordEvents ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None);
|
||||
|
||||
var parentSpan = (SpanSdk)tracer.StartSpan("parent", spanContext);
|
||||
var parentSpan = (SpanSdk)this.tracer.StartSpan("parent", spanContext);
|
||||
var parentActivity = parentSpan.Activity;
|
||||
var parentScope = this.tracer.WithSpan(parentSpan);
|
||||
|
||||
var childSpan = (SpanSdk)tracer.StartSpan("child");
|
||||
var childSpan = (SpanSdk)this.tracer.StartSpan("child");
|
||||
Assert.Same(parentSpan, this.tracer.CurrentSpan);
|
||||
using (this.tracer.WithSpan(childSpan, endSpan))
|
||||
{
|
||||
|
|
@ -283,7 +282,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void WithSpan_SameActivityCreateScopeTwice()
|
||||
{
|
||||
var span = (SpanSdk)tracer.StartRootSpan("foo");
|
||||
var span = (SpanSdk)this.tracer.StartRootSpan("foo");
|
||||
|
||||
using (var scope1 = this.tracer.WithSpan(span))
|
||||
{
|
||||
|
|
@ -304,7 +303,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void WithSpan_NullActivity()
|
||||
{
|
||||
var span = (SpanSdk)tracer.StartRootSpan("foo");
|
||||
var span = (SpanSdk)this.tracer.StartRootSpan("foo");
|
||||
|
||||
span.Activity.Stop();
|
||||
|
||||
|
|
@ -338,7 +337,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
{
|
||||
var spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), recordEvents ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None);
|
||||
|
||||
var span = (SpanSdk)tracer.StartSpan("foo", spanContext);
|
||||
var span = (SpanSdk)this.tracer.StartSpan("foo", spanContext);
|
||||
Assert.False(this.tracer.CurrentSpan.Context.IsValid);
|
||||
using (this.tracer.WithSpan(span))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void FromDescriptionAndAttributes_NullAttributes()
|
||||
{
|
||||
var evnt = new Event("", DateTime.UtcNow, null);
|
||||
var evnt = new Event(string.Empty, DateTime.UtcNow, null);
|
||||
Assert.Empty(evnt.Attributes);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,31 +35,6 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
private static readonly TimeSpan DefaultDelay = TimeSpan.FromMilliseconds(30);
|
||||
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(1);
|
||||
|
||||
private SpanSdk CreateSampledEndedSpan(string spanName, SpanProcessor spanProcessor)
|
||||
{
|
||||
var tracer = TracerFactory.Create(b => b
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(p => p.AddProcessor(e => spanProcessor))
|
||||
.SetTracerOptions(new TracerConfiguration())).GetTracer(null);
|
||||
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
|
||||
var span = (SpanSdk)tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
|
||||
private SpanSdk CreateNotSampledEndedSpan(string spanName, SpanProcessor spanProcessor)
|
||||
{
|
||||
var tracer = TracerFactory.Create(b => b
|
||||
.SetSampler(new AlwaysOffSampler())
|
||||
.AddProcessorPipeline(p => p.AddProcessor(_ => spanProcessor))
|
||||
.SetTracerOptions(new TracerConfiguration())).GetTracer(null);
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);
|
||||
var span = (SpanSdk)tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowsOnInvalidArguments()
|
||||
{
|
||||
|
|
@ -194,7 +169,6 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
Assert.Contains(new SpanData(span6), exported);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ExportNotSampledSpans()
|
||||
{
|
||||
|
|
@ -203,6 +177,7 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
using var spanProcessor = new BatchingSpanProcessor(spanExporter, 128, DefaultDelay, 3);
|
||||
var span1 = this.CreateNotSampledEndedSpan(SpanName1, spanProcessor);
|
||||
var span2 = this.CreateSampledEndedSpan(SpanName2, spanProcessor);
|
||||
|
||||
// Spans are recorded and exported in the same order as they are ended, we test that a non
|
||||
// sampled span is not exported by creating and ending a sampled span after a non sampled span
|
||||
// and checking that the first exported span is the sampled span (the non sampled did not get
|
||||
|
|
@ -314,10 +289,12 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
spans.Add(CreateSampledEndedSpan(i.ToString(), spanProcessor));
|
||||
spans.Add(this.CreateSampledEndedSpan(i.ToString(), spanProcessor));
|
||||
}
|
||||
|
||||
Assert.True(spanExporter.ExportedSpans.Length < spans.Count);
|
||||
}
|
||||
|
||||
Assert.True(spanExporter.WasShutDown);
|
||||
Assert.Equal(spans.Count, spanExporter.ExportedSpans.Length);
|
||||
Assert.Equal(spans.Count / batchSize, exportCalledCount);
|
||||
|
|
@ -336,10 +313,36 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
Assert.True(exporter.ExportedSpans.Length >= spanCount,
|
||||
Assert.True(
|
||||
exporter.ExportedSpans.Length >= spanCount,
|
||||
$"Expected at least {spanCount}, got {exporter.ExportedSpans.Length}");
|
||||
|
||||
return exporter.ExportedSpans;
|
||||
}
|
||||
|
||||
private SpanSdk CreateSampledEndedSpan(string spanName, SpanProcessor spanProcessor)
|
||||
{
|
||||
var tracer = TracerFactory.Create(b => b
|
||||
.SetSampler(new AlwaysOnSampler())
|
||||
.AddProcessorPipeline(p => p.AddProcessor(e => spanProcessor))
|
||||
.SetTracerOptions(new TracerConfiguration())).GetTracer(null);
|
||||
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
|
||||
var span = (SpanSdk)tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
|
||||
private SpanSdk CreateNotSampledEndedSpan(string spanName, SpanProcessor spanProcessor)
|
||||
{
|
||||
var tracer = TracerFactory.Create(b => b
|
||||
.SetSampler(new AlwaysOffSampler())
|
||||
.AddProcessorPipeline(p => p.AddProcessor(_ => spanProcessor))
|
||||
.SetTracerOptions(new TracerConfiguration())).GetTracer(null);
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);
|
||||
var span = (SpanSdk)tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,32 +35,15 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
|
||||
public SimpleSpanProcessorTest()
|
||||
{
|
||||
spanExporter = new TestExporter(null);
|
||||
tracer = TracerFactory.Create(b => b
|
||||
this.spanExporter = new TestExporter(null);
|
||||
this.tracer = TracerFactory.Create(b => b
|
||||
.AddProcessorPipeline(p => p
|
||||
.SetExporter(spanExporter)
|
||||
.SetExporter(this.spanExporter)
|
||||
.SetExportingProcessor(e => new SimpleSpanProcessor(e)))
|
||||
.SetSampler(new AlwaysParentSampler()))
|
||||
.GetTracer(null);
|
||||
}
|
||||
|
||||
private SpanSdk CreateSampledEndedSpan(string spanName)
|
||||
{
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
|
||||
var span = (SpanSdk)tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
|
||||
private SpanSdk CreateNotSampledEndedSpan(string spanName)
|
||||
{
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);
|
||||
var span = (SpanSdk)tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ThrowsOnNullExporter()
|
||||
{
|
||||
|
|
@ -70,15 +53,15 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
[Fact]
|
||||
public void ThrowsInExporter()
|
||||
{
|
||||
spanExporter = new TestExporter(_ => throw new ArgumentException("123"));
|
||||
tracer = TracerFactory.Create(b => b
|
||||
this.spanExporter = new TestExporter(_ => throw new ArgumentException("123"));
|
||||
this.tracer = TracerFactory.Create(b => b
|
||||
.AddProcessorPipeline(p => p
|
||||
.SetExporter(spanExporter)
|
||||
.SetExporter(this.spanExporter)
|
||||
.SetExportingProcessor(e => new SimpleSpanProcessor(e))))
|
||||
.GetTracer(null);
|
||||
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
|
||||
var span = (SpanSdk)tracer.StartSpan("foo", context);
|
||||
var span = (SpanSdk)this.tracer.StartSpan("foo", context);
|
||||
|
||||
// does not throw
|
||||
span.End();
|
||||
|
|
@ -87,15 +70,15 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
[Fact]
|
||||
public void ProcessorDoesNotBlockOnExporter()
|
||||
{
|
||||
spanExporter = new TestExporter(async _ => await Task.Delay(500));
|
||||
tracer = TracerFactory.Create(b => b
|
||||
this.spanExporter = new TestExporter(async _ => await Task.Delay(500));
|
||||
this.tracer = TracerFactory.Create(b => b
|
||||
.AddProcessorPipeline(p => p
|
||||
.SetExporter(spanExporter)
|
||||
.SetExporter(this.spanExporter)
|
||||
.SetExportingProcessor(e => new SimpleSpanProcessor(e))))
|
||||
.GetTracer(null);
|
||||
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
|
||||
var span = (SpanSdk)tracer.StartSpan("foo", context);
|
||||
var span = (SpanSdk)this.tracer.StartSpan("foo", context);
|
||||
|
||||
// does not block
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
|
@ -104,12 +87,11 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
|
||||
Assert.InRange(sw.Elapsed, TimeSpan.Zero, TimeSpan.FromMilliseconds(100));
|
||||
|
||||
var exported = WaitForSpans(spanExporter, 1, TimeSpan.FromMilliseconds(600));
|
||||
var exported = this.WaitForSpans(this.spanExporter, 1, TimeSpan.FromMilliseconds(600));
|
||||
|
||||
Assert.Single(exported);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task ShutdownTwice()
|
||||
{
|
||||
|
|
@ -124,10 +106,10 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
[Fact]
|
||||
public void ExportDifferentSampledSpans()
|
||||
{
|
||||
var span1 = CreateSampledEndedSpan(SpanName1);
|
||||
var span2 = CreateSampledEndedSpan(SpanName2);
|
||||
var span1 = this.CreateSampledEndedSpan(SpanName1);
|
||||
var span2 = this.CreateSampledEndedSpan(SpanName2);
|
||||
|
||||
var exported = WaitForSpans(spanExporter, 2, TimeSpan.FromMilliseconds(100));
|
||||
var exported = this.WaitForSpans(this.spanExporter, 2, TimeSpan.FromMilliseconds(100));
|
||||
Assert.Equal(2, exported.Length);
|
||||
Assert.Contains(new SpanData(span1), exported);
|
||||
Assert.Contains(new SpanData(span2), exported);
|
||||
|
|
@ -136,14 +118,15 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
[Fact]
|
||||
public void ExportNotSampledSpans()
|
||||
{
|
||||
var span1 = CreateNotSampledEndedSpan(SpanName1);
|
||||
var span2 = CreateSampledEndedSpan(SpanName2);
|
||||
var span1 = this.CreateNotSampledEndedSpan(SpanName1);
|
||||
var span2 = this.CreateSampledEndedSpan(SpanName2);
|
||||
|
||||
// Spans are recorded and exported in the same order as they are ended, we test that a non
|
||||
// sampled span is not exported by creating and ending a sampled span after a non sampled span
|
||||
// and checking that the first exported span is the sampled span (the non sampled did not get
|
||||
// exported).
|
||||
|
||||
var exported = WaitForSpans(spanExporter, 1, TimeSpan.FromMilliseconds(100));
|
||||
var exported = this.WaitForSpans(this.spanExporter, 1, TimeSpan.FromMilliseconds(100));
|
||||
|
||||
// Need to check this because otherwise the variable span1 is unused, other option is to not
|
||||
// have a span1 variable.
|
||||
|
|
@ -153,14 +136,31 @@ namespace OpenTelemetry.Trace.Export.Test
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
spanExporter.ShutdownAsync(CancellationToken.None);
|
||||
this.spanExporter.ShutdownAsync(CancellationToken.None);
|
||||
Activity.Current = null;
|
||||
}
|
||||
|
||||
private SpanSdk CreateSampledEndedSpan(string spanName)
|
||||
{
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.Recorded);
|
||||
var span = (SpanSdk)this.tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
|
||||
private SpanSdk CreateNotSampledEndedSpan(string spanName)
|
||||
{
|
||||
var context = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);
|
||||
var span = (SpanSdk)this.tracer.StartSpan(spanName, context);
|
||||
span.End();
|
||||
return span;
|
||||
}
|
||||
|
||||
private SpanData[] WaitForSpans(TestExporter exporter, int spanCount, TimeSpan timeout)
|
||||
{
|
||||
Assert.True(
|
||||
SpinWait.SpinUntil(() =>
|
||||
SpinWait.SpinUntil(
|
||||
() =>
|
||||
{
|
||||
Thread.Sleep(0);
|
||||
return exporter.ExportedSpans.Length >= spanCount;
|
||||
|
|
@ -27,36 +27,36 @@ namespace OpenTelemetry.Trace.Test
|
|||
|
||||
public LinkTest()
|
||||
{
|
||||
spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);
|
||||
this.spanContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);
|
||||
|
||||
attributesMap.Add("MyAttributeKey0", "MyStringAttribute");
|
||||
attributesMap.Add("MyAttributeKey1", 10L);
|
||||
attributesMap.Add("MyAttributeKey2", true);
|
||||
attributesMap.Add("MyAttributeKey3", 0.005);
|
||||
this.attributesMap.Add("MyAttributeKey0", "MyStringAttribute");
|
||||
this.attributesMap.Add("MyAttributeKey1", 10L);
|
||||
this.attributesMap.Add("MyAttributeKey2", true);
|
||||
this.attributesMap.Add("MyAttributeKey3", 0.005);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromSpanContext()
|
||||
{
|
||||
var link = new Link(spanContext);
|
||||
Assert.Equal(spanContext.TraceId, link.Context.TraceId);
|
||||
Assert.Equal(spanContext.SpanId, link.Context.SpanId);
|
||||
var link = new Link(this.spanContext);
|
||||
Assert.Equal(this.spanContext.TraceId, link.Context.TraceId);
|
||||
Assert.Equal(this.spanContext.SpanId, link.Context.SpanId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromSpanContext_WithAttributes()
|
||||
{
|
||||
var link = new Link(spanContext, attributesMap);
|
||||
Assert.Equal(spanContext.TraceId, link.Context.TraceId);
|
||||
Assert.Equal(spanContext.SpanId, link.Context.SpanId);
|
||||
Assert.Equal(attributesMap, link.Attributes);
|
||||
var link = new Link(this.spanContext, this.attributesMap);
|
||||
Assert.Equal(this.spanContext.TraceId, link.Context.TraceId);
|
||||
Assert.Equal(this.spanContext.SpanId, link.Context.SpanId);
|
||||
Assert.Equal(this.attributesMap, link.Attributes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality()
|
||||
{
|
||||
var link1 = new Link(spanContext);
|
||||
var link2 = new Link(spanContext);
|
||||
var link1 = new Link(this.spanContext);
|
||||
var link2 = new Link(this.spanContext);
|
||||
|
||||
Assert.Equal(link1, link2);
|
||||
Assert.True(link1 == link2);
|
||||
|
|
@ -65,8 +65,8 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void Equality_WithAttributes()
|
||||
{
|
||||
var link1 = new Link(spanContext, attributesMap);
|
||||
var link2 = new Link(spanContext, attributesMap);
|
||||
var link1 = new Link(this.spanContext, this.attributesMap);
|
||||
var link2 = new Link(this.spanContext, this.attributesMap);
|
||||
|
||||
Assert.Equal(link1, link2);
|
||||
Assert.True(link1 == link2);
|
||||
|
|
@ -85,8 +85,8 @@ namespace OpenTelemetry.Trace.Test
|
|||
[Fact]
|
||||
public void NotEquality_WithAttributes()
|
||||
{
|
||||
var link1 = new Link(spanContext, new Dictionary<string, object>());
|
||||
var link2 = new Link(spanContext, this.attributesMap);
|
||||
var link1 = new Link(this.spanContext, new Dictionary<string, object>());
|
||||
var link2 = new Link(this.spanContext, this.attributesMap);
|
||||
|
||||
Assert.NotEqual(link1, link2);
|
||||
Assert.True(link1 != link2);
|
||||
|
|
|
|||
|
|
@ -25,21 +25,27 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
public class B3FormatTest
|
||||
{
|
||||
private const string TraceIdBase16 = "ff000000000000000000000000000041";
|
||||
private static readonly ActivityTraceId TraceId = ActivityTraceId.CreateFromString(TraceIdBase16.AsSpan());
|
||||
private const string TraceIdBase16EightBytes = "0000000000000041";
|
||||
private static readonly ActivityTraceId TraceIdEightBytes = ActivityTraceId.CreateFromString(("0000000000000000" + TraceIdBase16EightBytes).AsSpan());
|
||||
private const string SpanIdBase16 = "ff00000000000041";
|
||||
private static readonly ActivitySpanId SpanId = ActivitySpanId.CreateFromString(SpanIdBase16.AsSpan());
|
||||
|
||||
private const string InvalidId = "abcdefghijklmnop";
|
||||
private const string InvalidSizeId = "0123456789abcdef00";
|
||||
|
||||
private const ActivityTraceFlags TraceOptions = ActivityTraceFlags.Recorded;
|
||||
|
||||
private static readonly ActivityTraceId TraceId = ActivityTraceId.CreateFromString(TraceIdBase16.AsSpan());
|
||||
private static readonly ActivityTraceId TraceIdEightBytes = ActivityTraceId.CreateFromString(("0000000000000000" + TraceIdBase16EightBytes).AsSpan());
|
||||
private static readonly ActivitySpanId SpanId = ActivitySpanId.CreateFromString(SpanIdBase16.AsSpan());
|
||||
|
||||
private static readonly Action<IDictionary<string, string>, string, string> Setter = (d, k, v) => d[k] = v;
|
||||
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> Getter =
|
||||
(d, k) =>
|
||||
{
|
||||
d.TryGetValue(k, out var v);
|
||||
return new string[] { v };
|
||||
};
|
||||
|
||||
private readonly B3Format b3Format = new B3Format();
|
||||
private readonly B3Format b3FormatSingleHeader = new B3Format(true);
|
||||
|
||||
private static readonly Action<IDictionary<string, string>, string, string> Setter = (d, k, v) => d[k] = v;
|
||||
private static readonly Func<IDictionary<string, string>, string, IEnumerable<string>> Getter = (d, k) => { d.TryGetValue(k, out var v); return new string[] { v }; };
|
||||
private readonly ITestOutputHelper output;
|
||||
|
||||
public B3FormatTest(ITestOutputHelper output)
|
||||
|
|
@ -51,8 +57,8 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
public void Serialize_SampledContext()
|
||||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
b3Format.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" } });
|
||||
this.b3Format.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, Setter);
|
||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -60,9 +66,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
var context = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
output.WriteLine(context.ToString());
|
||||
b3Format.Inject(context, carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 } });
|
||||
this.output.WriteLine(context.ToString());
|
||||
this.b3Format.Inject(context, carrier, Setter);
|
||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -70,10 +76,10 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersNotSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 },
|
||||
};
|
||||
var spanContext = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
Assert.Equal(spanContext, b3Format.Extract(headersNotSampled, Getter));
|
||||
Assert.Equal(spanContext, this.b3Format.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -81,9 +87,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Sampled, "1"},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "1" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3Format.Extract(headersSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), this.b3Format.Extract(headersSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -91,9 +97,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersNotSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Sampled, "0"},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Sampled, "0" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersNotSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), this.b3Format.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -101,9 +107,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersFlagSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Flags, "1"},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Flags, "1" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3Format.Extract(headersFlagSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), this.b3Format.Extract(headersFlagSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -111,9 +117,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersFlagNotSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, SpanIdBase16}, {B3Format.XB3Flags, "0"},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, SpanIdBase16 }, { B3Format.XB3Flags, "0" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersFlagNotSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), this.b3Format.Extract(headersFlagNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -121,11 +127,11 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersEightBytes = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16EightBytes},
|
||||
{B3Format.XB3SpanId, SpanIdBase16},
|
||||
{B3Format.XB3Sampled, "1"},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16EightBytes },
|
||||
{ B3Format.XB3SpanId, SpanIdBase16 },
|
||||
{ B3Format.XB3Sampled, "1" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), b3Format.Extract(headersEightBytes, Getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), this.b3Format.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -133,9 +139,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersEightBytes = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16EightBytes}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16EightBytes }, { B3Format.XB3SpanId, SpanIdBase16 },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), b3Format.Extract(headersEightBytes, Getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), this.b3Format.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -143,9 +149,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, InvalidId}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
{ B3Format.XB3TraceId, InvalidId }, { B3Format.XB3SpanId, SpanIdBase16 },
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -153,17 +159,17 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, InvalidSizeId}, {B3Format.XB3SpanId, SpanIdBase16},
|
||||
{ B3Format.XB3TraceId, InvalidSizeId }, { B3Format.XB3SpanId, SpanIdBase16 },
|
||||
};
|
||||
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingTraceId()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3SpanId, SpanIdBase16 }, };
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -171,9 +177,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, InvalidId},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, InvalidId },
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -181,24 +187,24 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3TraceId, TraceIdBase16}, {B3Format.XB3SpanId, InvalidSizeId},
|
||||
{ B3Format.XB3TraceId, TraceIdBase16 }, { B3Format.XB3SpanId, InvalidSizeId },
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingSpanId()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3TraceId, TraceIdBase16 } };
|
||||
Assert.Equal(SpanContext.BlankRemote, b3Format.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3Format.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_SampledContext_SingleHeader()
|
||||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
b3FormatSingleHeader.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } });
|
||||
this.b3FormatSingleHeader.Inject(new SpanContext(TraceId, SpanId, TraceOptions), carrier, Setter);
|
||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -206,9 +212,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var carrier = new Dictionary<string, string>();
|
||||
var context = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
output.WriteLine(context.ToString());
|
||||
b3FormatSingleHeader.Inject(context, carrier, Setter);
|
||||
ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } });
|
||||
this.output.WriteLine(context.ToString());
|
||||
this.b3FormatSingleHeader.Inject(context, carrier, Setter);
|
||||
this.ContainsExactly(carrier, new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" } });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -216,10 +222,10 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersNotSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}" },
|
||||
};
|
||||
var spanContext = new SpanContext(TraceId, SpanId, ActivityTraceFlags.None);
|
||||
Assert.Equal(spanContext, b3FormatSingleHeader.Extract(headersNotSampled, Getter));
|
||||
Assert.Equal(spanContext, this.b3FormatSingleHeader.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -227,9 +233,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), this.b3FormatSingleHeader.Extract(headersSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -237,9 +243,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersNotSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersNotSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), this.b3FormatSingleHeader.Extract(headersNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -247,9 +253,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersFlagSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-1" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersFlagSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, TraceOptions), this.b3FormatSingleHeader.Extract(headersFlagSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -257,9 +263,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersFlagNotSampled = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{SpanIdBase16}-0" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersFlagNotSampled, Getter));
|
||||
Assert.Equal(new SpanContext(TraceId, SpanId, ActivityTraceFlags.None), this.b3FormatSingleHeader.Extract(headersFlagNotSampled, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -267,9 +273,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersEightBytes = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}-1"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}-1" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), b3FormatSingleHeader.Extract(headersEightBytes, Getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, TraceOptions), this.b3FormatSingleHeader.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -277,9 +283,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var headersEightBytes = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16EightBytes}-{SpanIdBase16}" },
|
||||
};
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), b3FormatSingleHeader.Extract(headersEightBytes, Getter));
|
||||
Assert.Equal(new SpanContext(TraceIdEightBytes, SpanId, ActivityTraceFlags.None), this.b3FormatSingleHeader.Extract(headersEightBytes, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -287,9 +293,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{InvalidId}-{SpanIdBase16}"},
|
||||
{ B3Format.XB3Combined, $"{InvalidId}-{SpanIdBase16}" },
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -297,17 +303,17 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{InvalidSizeId}-{SpanIdBase16}"},
|
||||
{ B3Format.XB3Combined, $"{InvalidSizeId}-{SpanIdBase16}" },
|
||||
};
|
||||
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingTraceId_SingleHeader()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3Combined, $"-{SpanIdBase16}" } };
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -315,9 +321,9 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidId}"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidId}" },
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -325,22 +331,23 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
var invalidHeaders = new Dictionary<string, string>
|
||||
{
|
||||
{B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidSizeId}"},
|
||||
{ B3Format.XB3Combined, $"{TraceIdBase16}-{InvalidSizeId}" },
|
||||
};
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParseMissingSpanId_SingleHeader()
|
||||
{
|
||||
var invalidHeaders = new Dictionary<string, string> { { B3Format.XB3Combined, $"{TraceIdBase16}-" } };
|
||||
Assert.Equal(SpanContext.BlankRemote, b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
Assert.Equal(SpanContext.BlankRemote, this.b3FormatSingleHeader.Extract(invalidHeaders, Getter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Fields_list()
|
||||
{
|
||||
ContainsExactly(b3Format.Fields,
|
||||
this.ContainsExactly(
|
||||
this.b3Format.Fields,
|
||||
new List<string> { B3Format.XB3TraceId, B3Format.XB3SpanId, B3Format.XB3ParentSpanId, B3Format.XB3Sampled, B3Format.XB3Flags });
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +364,7 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
{
|
||||
foreach (var d in dict)
|
||||
{
|
||||
output.WriteLine(d.Key + "=" + d.Value);
|
||||
this.output.WriteLine(d.Key + "=" + d.Value);
|
||||
}
|
||||
|
||||
Assert.Equal(items.Count, dict.Count);
|
||||
|
|
@ -368,4 +375,3 @@ namespace OpenTelemetry.Context.Propagation.Test
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-01"},
|
||||
{TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01"},
|
||||
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
|
||||
{ TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01" },
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
|
|
@ -76,7 +76,7 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-00"},
|
||||
{ TraceParent, $"00-{TraceId}-{SpanId}-00" },
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
|
|
@ -106,7 +106,7 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{TraceParent, $"00-xyz7651916cd43dd8448eb211c80319c-{SpanId}-01"},
|
||||
{ TraceParent, $"00-xyz7651916cd43dd8448eb211c80319c-{SpanId}-01" },
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
|
|
@ -121,7 +121,7 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-01"},
|
||||
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
|
|
@ -136,8 +136,8 @@ namespace OpenTelemetry.Impl.Trace.Propagation
|
|||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{TraceParent, $"00-{TraceId}-{SpanId}-01"},
|
||||
{TraceState, "k1=v1,k2=v2,k3=v3" },
|
||||
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
|
||||
{ TraceState, "k1=v1,k2=v2,k3=v3" },
|
||||
};
|
||||
|
||||
var f = new TraceContextFormat();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// <copyright file="StringExtensionsTests.cs" company="OpenTelemetry Authors">
|
||||
// <copyright file="TracestateUtilsTests.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
|
@ -60,7 +60,8 @@ namespace OpenTelemetry.Tests.Impl.Trace.Propagation
|
|||
"k0=v,k1=v,k2=v,k3=v,k4=v,k5=v,k6=v,k7=v1,k8=v,k9=v,k10=v,k11=v,k12=v,k13=v,k14=v,k15=v,k16=v,k17=v,k18=v,k19=v,k20=v,k21=v,k22=v,k23=v,k24=v,k25=v,k26=v,k27=v1,k28=v,k29=v,k30=v,k31=v";
|
||||
Assert.True(TracestateUtils.AppendTracestate(tracestate, tracestateEntries));
|
||||
Assert.Equal(32, tracestateEntries.Count);
|
||||
Assert.Equal("k0=v,k1=v,k2=v,k3=v,k4=v,k5=v,k6=v,k7=v1,k8=v,k9=v,k10=v,k11=v,k12=v,k13=v,k14=v,k15=v,k16=v,k17=v,k18=v,k19=v,k20=v,k21=v,k22=v,k23=v,k24=v,k25=v,k26=v,k27=v1,k28=v,k29=v,k30=v,k31=v",
|
||||
Assert.Equal(
|
||||
"k0=v,k1=v,k2=v,k3=v,k4=v,k5=v,k6=v,k7=v1,k8=v,k9=v,k10=v,k11=v,k12=v,k13=v,k14=v,k15=v,k16=v,k17=v,k18=v,k19=v,k20=v,k21=v,k22=v,k23=v,k24=v,k25=v,k26=v,k27=v1,k28=v,k29=v,k30=v,k31=v",
|
||||
TracestateUtils.GetString(tracestateEntries));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,10 @@
|
|||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Trace;
|
||||
using OpenTelemetry.Trace.Configuration;
|
||||
using OpenTelemetry.Utils;
|
||||
using System.Linq;
|
||||
using OpenTelemetry.Context.Propagation;
|
||||
using OpenTelemetry.Trace;
|
||||
using Xunit;
|
||||
|
||||
namespace OpenTelemetry.Tests.Impl.Trace
|
||||
|
|
@ -38,6 +37,7 @@ namespace OpenTelemetry.Tests.Impl.Trace
|
|||
{
|
||||
var noopScope = new ProxyTracer().WithSpan(BlankSpan.Instance);
|
||||
Assert.NotNull(noopScope);
|
||||
|
||||
// does not throw
|
||||
noopScope.Dispose();
|
||||
}
|
||||
|
|
@ -231,7 +231,9 @@ namespace OpenTelemetry.Tests.Impl.Trace
|
|||
using (proxyTracer.WithSpan(parentSpan))
|
||||
{
|
||||
var startTimestamp = PreciseTimestamp.GetUtcNow();
|
||||
var linkContext = new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(),
|
||||
var linkContext = new SpanContext(
|
||||
ActivityTraceId.CreateRandom(),
|
||||
ActivitySpanId.CreateRandom(),
|
||||
ActivityTraceFlags.Recorded);
|
||||
var span = (SpanSdk)proxyTracer.StartSpan("child", SpanKind.Consumer, new SpanCreationOptions
|
||||
{
|
||||
|
|
@ -255,4 +257,3 @@ namespace OpenTelemetry.Tests.Impl.Trace
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue