Skip to content

Commit

Permalink
Include process information in metadata stanza when emiting events to…
Browse files Browse the repository at this point in the history
… apm-server
  • Loading branch information
Mpdreamz committed Feb 1, 2024
1 parent 66113a7 commit 973d8b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Elastic.Apm/Model/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class Metadata
// ReSharper disable once UnusedAutoPropertyAccessor.Global - used by Json.Net
public Service Service { get; set; }

public ProcessInformation Process { get; set; }

// ReSharper disable once UnusedAutoPropertyAccessor.Global
public Api.System System { get; set; }

Expand Down
22 changes: 22 additions & 0 deletions src/Elastic.Apm/Model/ProcessInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to Elasticsearch B.V under
// one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Diagnostics;

namespace Elastic.Apm.Model;

internal class ProcessInformation
{
public int Pid { get; set; }

public string Title { get; set; }

public static ProcessInformation Create()
{
var p = Process.GetCurrentProcess();
return new ProcessInformation { Pid = p.Id, Title = p.ProcessName };
}

}
3 changes: 2 additions & 1 deletion src/Elastic.Apm/Report/PayloadSenderV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public PayloadSenderV2(
_cloudMetadataProviderCollection = new CloudMetadataProviderCollection(configuration.CloudProvider, _logger, environmentVariables);
_apmServerInfo = apmServerInfo ?? new ApmServerInfo();
_serverInfoCallback = serverInfoCallback;
_metadata = new Metadata { Service = service, System = System };
var process = ProcessInformation.Create();
_metadata = new Metadata { Service = service, System = System, Process = process};
foreach (var globalLabelKeyValue in configuration.GlobalLabels)
_metadata.Labels.Add(globalLabelKeyValue.Key, globalLabelKeyValue.Value);
_cachedActivationMethod = _metadata.Service?.Agent.ActivationMethod;
Expand Down

0 comments on commit 973d8b1

Please sign in to comment.