diff --git a/src/Elastic.Apm/Api/ProcessInformation.cs b/src/Elastic.Apm/Api/ProcessInformation.cs new file mode 100644 index 000000000..83187979e --- /dev/null +++ b/src/Elastic.Apm/Api/ProcessInformation.cs @@ -0,0 +1,30 @@ +// 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; +using Elastic.Apm.Api.Constraints; +using Elastic.Apm.Helpers; + +namespace Elastic.Apm.Api; + +internal class ProcessInformation +{ + public int Pid { get; set; } + + [MaxLength] + public string Title { get; set; } + + public static ProcessInformation Create() + { + var p = Process.GetCurrentProcess(); + return new ProcessInformation { Pid = p.Id, Title = p.ProcessName }; + } + + public override string ToString() => new ToStringBuilder(nameof(Service)) + { + { nameof(Pid), Pid }, + { nameof(Title), Title } + }.ToString(); +} diff --git a/src/Elastic.Apm/Model/Metadata.cs b/src/Elastic.Apm/Model/Metadata.cs index 7ac8940b9..38fc9eeed 100644 --- a/src/Elastic.Apm/Model/Metadata.cs +++ b/src/Elastic.Apm/Model/Metadata.cs @@ -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; } diff --git a/src/Elastic.Apm/Report/PayloadSenderV2.cs b/src/Elastic.Apm/Report/PayloadSenderV2.cs index 65ac6461b..df4b52fde 100644 --- a/src/Elastic.Apm/Report/PayloadSenderV2.cs +++ b/src/Elastic.Apm/Report/PayloadSenderV2.cs @@ -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; diff --git a/test/Elastic.Apm.Tests.MockApmServer/MetadataDto.cs b/test/Elastic.Apm.Tests.MockApmServer/MetadataDto.cs index e72fd9963..93b992bb3 100644 --- a/test/Elastic.Apm.Tests.MockApmServer/MetadataDto.cs +++ b/test/Elastic.Apm.Tests.MockApmServer/MetadataDto.cs @@ -6,6 +6,7 @@ using Elastic.Apm.Api; using Elastic.Apm.Config; using Elastic.Apm.Helpers; +using Elastic.Apm.Model; // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedAutoPropertyAccessor.Global @@ -17,6 +18,7 @@ namespace Elastic.Apm.Tests.MockApmServer internal class MetadataDto : IDto { public Service Service { get; set; } + public ProcessInformation Process { get; set; } public Api.System System { get; set; } public Api.Cloud Cloud { get; set; } public Dictionary Labels { get; set; } @@ -25,6 +27,7 @@ public override string ToString() => new ToStringBuilder(nameof(MetadataDto)) { { nameof(Service), Service }, + { nameof(Process), Process }, { nameof(System), System }, { nameof(Labels), AbstractConfigurationReader.ToLogString(Labels) }, { nameof(Cloud), Cloud },