Skip to content

Commit

Permalink
fix some compatibility bugs (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhaoyang authored Mar 31, 2024
1 parent 6900a0f commit e7633b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<VersionMajor>2</VersionMajor>
<VersionMinor>1</VersionMinor>
<VersionMinor>2</VersionMinor>
<VersionPatch>0</VersionPatch>
<VersionQuality></VersionQuality>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
Expand Down
21 changes: 15 additions & 6 deletions src/SkyApm.Agent.Hosting/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,43 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddSkyAPM(this IServiceCollection services, Action<SkyApmExtensions> extensionsSetup = null)
public static IServiceCollection AddSkyAPM(this IServiceCollection services,
Action<SkyApmExtensions> extensionsSetup = null)
{
#region can be optimized

string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (environment == null || environment.Length < 1)
{
environment = "Development";
}

IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddJsonFile("skyapm.json", true);
configurationBuilder.AddJsonFile("skyapm." + environment + ".json", true);
IConfiguration configuration = configurationBuilder.Build();
string enable = configuration?.GetSection("SkyWalking:Enable").Value ?? "false";
if (null == enable || !"true".Equals(enable.ToLower()))
string enable = configuration?.GetSection("SkyWalking:Enable").Value;
if (enable != null && "false".Equals(enable.ToLower()))
{
return services;
}

string serviceName = configuration?.GetSection("SkyWalking:ServiceName").Value ?? "";
if (null == serviceName || serviceName.Length < 1)
{
return services;
}

Environment.SetEnvironmentVariable("SKYWALKING__SERVICENAME", serviceName);

#endregion

services.AddSkyAPMCore(extensionsSetup);
return services;
}

private static IServiceCollection AddSkyAPMCore(this IServiceCollection services, Action<SkyApmExtensions> extensionsSetup = null)
private static IServiceCollection AddSkyAPMCore(this IServiceCollection services,
Action<SkyApmExtensions> extensionsSetup = null)
{
if (services == null)
{
Expand Down Expand Up @@ -125,7 +135,7 @@ private static IServiceCollection AddTracing(this IServiceCollection services)
services.AddSingleton<IBase64Formatter, Base64Formatter>();
return services;
}

private static IServiceCollection AddSampling(this IServiceCollection services)
{
services.AddSingleton<SimpleCountSamplingInterceptor>();
Expand Down Expand Up @@ -153,6 +163,5 @@ private static IServiceCollection AddSkyApmLogging(this IServiceCollection servi
services.AddSingleton<ILoggerFactory, DefaultLoggerFactory>();
return services;
}

}
}

0 comments on commit e7633b0

Please sign in to comment.