Skip to content

Commit

Permalink
Merge pull request #17 from digma-ai/alignments
Browse files Browse the repository at this point in the history
Small alignments
  • Loading branch information
asafchen-dig authored Nov 29, 2022
2 parents 9407d50 + 6a2cce2 commit 0045580
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ namespace OpenTelemetry.Instrumentation.Digma
public class DigmaConfigurationOptions
{
private const string DEFAULT_COMMIT_ENV_VAR = "DEPLOYMENT_COMMIT_ID";
private const string DEFAULT_ENV_ENV_VAR = "DEPLOYMENT_ENV";
private const string DEFAULT_DEPLOYMENT_ENV_ENV_VAR = "DEPLOYMENT_ENV";
private const string DEFAULT_DIGMA_ENV_ENV_VAR = "DIGMA_ENV";

public string? NamespaceRoot { get; set; } = null;
public string? Environment { get; set; } = null;
public string CommitIdEnvVariable { get; set; } = DEFAULT_COMMIT_ENV_VAR;
public string EnvironmentEnvVariable { get; set; } = DEFAULT_ENV_ENV_VAR;
[Obsolete($"Please use {nameof(DigmaEnvironmentEnvVariable)}")]
public string EnvironmentEnvVariable { get; set; } = DEFAULT_DEPLOYMENT_ENV_ENV_VAR;
public string DigmaEnvironmentEnvVariable { get; set; } = DEFAULT_DIGMA_ENV_ENV_VAR;
public string? CommitId { get; set; } = null;
public string? SpanMappingPattern { get; set; } = "";
public string? SpanMappingReplacement { get; set; } = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static ResourceBuilder AddDigmaAttributes(this ResourceBuilder builder,
Action<DigmaConfigurationOptions>? configure = null)
{
var workingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var hostName = Dns.GetHostName();

DigmaConfigurationOptions options = new DigmaConfigurationOptions();
if (configure != null)
Expand All @@ -37,13 +38,13 @@ public static ResourceBuilder AddDigmaAttributes(this ResourceBuilder builder,
}

//If namespace not provided try to get it from the calling method
if (string.IsNullOrEmpty(options.NamespaceRoot))
if (string.IsNullOrWhiteSpace(options.NamespaceRoot))
{
StackTrace stackTrace = new StackTrace();
options.NamespaceRoot = stackTrace?.GetFrame(1)?.GetMethod()?.DeclaringType?.Namespace ?? "";
}

if (string.IsNullOrEmpty(options.NamespaceRoot))
if (string.IsNullOrWhiteSpace(options.NamespaceRoot))
{
options.NamespaceRoot = Assembly.GetCallingAssembly().GetTypes()
.Where(x => x.Namespace != null)
Expand All @@ -53,23 +54,22 @@ public static ResourceBuilder AddDigmaAttributes(this ResourceBuilder builder,
.FirstOrDefault();
}

if (options.CommitId == null)
if (string.IsNullOrWhiteSpace(options.CommitId))
{
options.CommitId = Environment.GetEnvironmentVariable(options.CommitIdEnvVariable) ?? "";
}

var hostName = Dns.GetHostName();
if (options.Environment == null)
if (string.IsNullOrWhiteSpace(options.Environment))
{
options.Environment = Environment.GetEnvironmentVariable(options.DigmaEnvironmentEnvVariable) ?? "";
}
if (string.IsNullOrWhiteSpace(options.Environment))
{
options.Environment = Environment.GetEnvironmentVariable(options.EnvironmentEnvVariable) ?? "";
}
if (string.IsNullOrWhiteSpace(options.Environment))
{
var env = Environment.GetEnvironmentVariable(options.EnvironmentEnvVariable);
if (string.IsNullOrWhiteSpace(env))
{
options.Environment = hostName + "[local]";
}
else
{
options.Environment = env;
}
options.Environment = hostName + "[local]";
}

builder.AddAttributes(new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<PackageId>OpenTel.Instrumentation.Digma</PackageId>
<Version>0.6.10</Version>
<Version>0.6.11</Version>
<Authors>Digma Team</Authors>
<Company>Digma</Company>
<TargetFramework>net6.0</TargetFramework>
Expand Down

0 comments on commit 0045580

Please sign in to comment.