Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows script to install Splunk distro for .NET instead of SFx.NET #4343

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/win-package-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,20 @@ jobs:
name: msi-build
path: ./tests/zeroconfig/windows/testdata/docker-setup/

- name: Get latest signalfx-dotnet-tracing release
id: dotnet-tracing
- name: Get latest splunk-otel-dotnet release
id: dotnet-instrumentation
uses: pozetroninc/[email protected]
with:
owner: signalfx
repo: signalfx-dotnet-tracing
repo: splunk-otel-dotnet
excludes: prerelease, draft
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set SIGNALFX_DOTNET_TRACING_VERSION
- name: Set SPLUNK_OTEL_DOTNET_VERSION
run: |
version="${{ steps.dotnet-tracing.outputs.release }}"
sed -i "s|SIGNALFX_DOTNET_TRACING_VERSION|${version#v}|" tests/zeroconfig/windows/testdata/resource_traces/aspnetcore.yaml
sed -i "s|SIGNALFX_DOTNET_TRACING_VERSION|${version#v}|" tests/zeroconfig/windows/testdata/resource_traces/aspnetfx.yaml
version="${{ steps.dotnet-instrumentation.outputs.release }}"
sed -i "s|SPLUNK_OTEL_DOTNET_VERSION|${version#v}|" tests/zeroconfig/windows/testdata/resource_traces/aspnetcore.yaml
sed -i "s|SPLUNK_OTEL_DOTNET_VERSION|${version#v}|" tests/zeroconfig/windows/testdata/resource_traces/aspnetfx.yaml
shell: bash

- name: Run the test script
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

### 🛑 Breaking changes 🛑

- (Splunk) The Splunk OpenTelemetry Collector [Windows install script](https://docs.splunk.com/observability/en/gdi/opentelemetry/collector-windows/install-windows.html#install-the-collector-using-the-script)
now installs the [Splunk Distribution of OpenTelemetry .NET](https://docs.splunk.com/observability/en/gdi/get-data-in/application/otel-dotnet/get-started.html#instrument-net-applications-for-splunk-observability-cloud-opentelemetry)
instead of the [SignalFx Instrumentation for .NET](https://docs.splunk.com/observability/en/gdi/get-data-in/application/otel-dotnet/sfx/sfx-instrumentation.html#signalfx-instrumentation-for-net-deprecated)
when the parameter `-with_dotnet_instrumentation` is set to `$true` ([#4343](https://github.com/signalfx/splunk-otel-collector/pull/4343))

### 💡 Enhancements 💡

- (Splunk) Add a resource attribute to internal metrics to track discovery usage ([#4323](https://github.com/signalfx/splunk-otel-collector/pull/4323))
Expand Down
66 changes: 44 additions & 22 deletions internal/buildscripts/packaging/installer/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
.EXAMPLE
.\install.ps1 -access_token "ACCESSTOKEN" -with_fluentd $true
.PARAMETER with_dotnet_instrumentation
(OPTIONAL) Whether to install and configure .NET tracing to forward .NET application traces to the local collector (default: $false)
(OPTIONAL) Whether to install and configure the Splunk Distribution of OpenTelemetry .NET to forward .NET application telemetry to the local collector (default: $false).
.EXAMPLE
.\install.ps1 -access_token "ACCESSTOKEN" -with_dotnet_instrumentation $true
.PARAMETER deployment_env
(OPTIONAL) A system-wide SignalFx "environment" used by .NET instrumentation. Sets the SIGNALFX_ENV environment variable. Ignored if -with_dotnet_instrumentation is false.
(OPTIONAL) A system-wide "deployment.environment" set via the environment variable 'OTEL_RESOURCE_ATTRIBUTES' for the whole machine. Ignored if -with_dotnet_instrumentation is false.
.EXAMPLE
.\install.ps1 -access_token "ACCESSTOKEN" -with_dotnet_instrumentation $true -deployment_env staging
.PARAMETER bundle_dir
Expand Down Expand Up @@ -414,7 +414,7 @@ function download_collector_package([string]$collector_version=$collector_versio
}

# check registry for the agent msi package
function msi_installed([string]$name="Splunk OpenTelemetry Collector") {
function msi_installed([string]$name) {
return (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq $name }) -ne $null
}

Expand Down Expand Up @@ -471,7 +471,7 @@ if (!(check_if_admin)) {
echo 'Checking execution policy'
check_policy

if (msi_installed) {
if (msi_installed -name "Splunk OpenTelemetry Collector") {
throw "The Splunk OpenTelemetry Collector is already installed. Remove or uninstall the Collector and rerun this script."
}

Expand All @@ -491,16 +491,16 @@ if ($with_fluentd -And (Test-Path -Path "$fluentd_base_dir\bin\fluentd")) {
$tempdir = create_temp_dir -tempdir $tempdir

if ($with_dotnet_instrumentation) {
echo "Installing SignalFx Instrumentation for .NET ..."
$module_name = "Splunk.SignalFx.DotNet.psm1"
$download = "https://github.com/signalfx/signalfx-dotnet-tracing/releases/latest/download/Splunk.SignalFx.DotNet.psm1"
if ((msi_installed -name "SignalFx .NET Tracing 64-bit") -Or (msi_installed -name "SignalFx .NET Tracing 32-bit")) {
throw "SignalFx .NET Instrumentation is already installed. Stop all instrumented applications and uninstall SignalFx Instrumentation for .NET before running this script again."
}
echo "Downloading Splunk Distribution of OpenTelemetry .NET ..."
$module_name = "Splunk.OTel.DotNet.psm1"
$download = "https://github.com/signalfx/splunk-otel-dotnet/releases/latest/download/$module_name"
$dotnet_autoinstr_path = Join-Path $tempdir $module_name
echo "Downloading .NET Instrumentation installer ..."
Invoke-WebRequest -Uri $download -OutFile $dotnet_autoinstr_path -UseBasicParsing
Import-Module $dotnet_autoinstr_path
if (Get-IsSignalFxInstalled) {
throw "SignalFx Instrumentation for .NET is already installed. Remove or uninstall SignalFx Instrumentation for .NET and rerun this script."
}
}

if ($ingest_url -eq "") {
Expand Down Expand Up @@ -689,28 +689,50 @@ restarted to apply the changes by restarting the system or running the following
echo "$message"
}

$otel_resource_attributes = ""
if ($deployment_env -ne "") {
echo "Setting deployment environment to $deployment_env"
$otel_resource_attributes = "deployment.environment=$deployment_env"
} else {
echo "Deployment environment was not specified. Unless otherwise defined, will appear as 'unknown' in the UI."
}

if ($with_dotnet_instrumentation) {
echo "Installing SignalFx Dotnet Auto Instrumentation..."
Install-SignalFxDotnet
echo "Installing Splunk Distribution of OpenTelemetry .NET..."
$currentInstallVersion = Get-OpenTelemetryInstallVersion
if ($currentInstallVersion) {
throw "The Splunk Distribution of OpenTelemetry .NET is already installed. Stop all instrumented applications and uninstall it and then rerun this script."
}

$regkey = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
if ($deployment_env -ne "") {
echo "Setting SIGNALFX_ENV environment variable to $deployment_env ..."
update_registry -path "$regkey" -name "SIGNALFX_ENV" -value "$deployment_env"
} else {
echo "SIGNALFX_ENV environment variable not set. Unless otherwise defined, will appear as 'unknown' in the UI."
Install-OpenTelemetryCore

$installed_version = Get-OpenTelemetryInstallVersion
if ($otel_resource_attributes -ne "") {
$otel_resource_attributes += ","
}
$otel_resource_attributes += "splunk.zc.method=splunk-otel-dotnet-$installed_version"
}

if ($otel_resource_attributes -ne "") {
# The OTEL_RESOURCE_ATTRIBUTES environment variable must be set before restarting IIS.
$regkey = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
try {
$dotnet_version = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where { $_.DisplayName -eq "SignalFx .NET Tracing 64-bit" }).DisplayVersion
update_registry -path "$regkey" -name "SIGNALFX_GLOBAL_TAGS" "splunk.zc.method:signalfx-dotnet-tracing-${dotnet_version}"
update_registry -path "$regkey" -name "OTEL_RESOURCE_ATTRIBUTES" -value "$otel_resource_attributes"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to do here, but OTEL_RESOURCE_ATTRIBUTES seems to be conflicting with instrumenting agent and could leak to an instrumented process when in a global scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to change this on this PR but the main thing here to me is that the splunk.zc.method seems to need a different value since we could have multiple instrumentations on the same box. However, deployment.environment is something that we want for the whole machine. I will have a conversation with Rotel about it before changing it, the current code is in line with what mass deployments are doing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the conflict is getting even bigger then? ... since envs don't stack by default and OTEL_RESOURCE_ATTRIBUTES can be easily overwritten (due being a generic variable) by a client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to investigate this separately, likely also changing the value that we use for OTel resource attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After writing the answer to Aunsh I think it will make more sense to just bail out here: it will be consistent with what is done for the collector MSI: the script just bails out if there is already one version installed. We are also bailing out if SFx.NET is already installed.

} catch {
Write-Warning "Failed to set OTEL_RESOURCE_ATTRIBUTES environment variable."
continue
}
}

if ($with_dotnet_instrumentation) {
if (service_installed -name "W3SVC") {
echo "Registering OpenTelemetry for IIS..."
Register-OpenTelemetryForIIS
}

$message = "
SignalFx .NET Instrumentation has been installed and configured to forward traces to the Splunk OpenTelemetry Collector.
By default, .NET Instrumentation will automatically generate traces for applications running on IIS.
Splunk Distribution of OpenTelemetry for .NET has been installed and configured to forward traces to the Splunk OpenTelemetry Collector.
By default, the .NET instrumentation will automatically generate telemetry only for .NET applications running on IIS.
"
echo "$message"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/zeroconfig/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ a deployment following the Zero Configuration procedures.

## Requirements to run the tests locally

The GitHub job `windows-zeroconfig-e2e-test` in the [`build-and-test`](../../../.github/workflows/build-and-test.yml)
The GitHub job `dotnet-zeroconfig-e2e-test` in the [`build-and-test`](../../../.github/workflows/build-and-test.yml)
has the actual requirements to run the tests locally, overall one needs:

- Set up the [`./testdata/docker-setup`](./testdata/docker-setup) folder by adding:
Expand Down
44 changes: 27 additions & 17 deletions tests/zeroconfig/windows/testdata/resource_traces/aspnetcore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@ resource_spans:
deployment.environment: zc-iis-test
host.name: <ANY>
os.type: windows
process.pid: <ANY>
process.runtime.description: .NET 6.0.27
process.runtime.name: .NET
process.runtime.version: 6.0.27
pjanotti marked this conversation as resolved.
Show resolved Hide resolved
service.name: AspNetCore.WebApi.Net
splunk.distro.version: SPLUNK_OTEL_DOTNET_VERSION
splunk.zc.method: splunk-otel-dotnet-vSPLUNK_OTEL_DOTNET_VERSION
telemetry.distro.name: splunk-otel-dotnet
telemetry.distro.version: SPLUNK_OTEL_DOTNET_VERSION
telemetry.sdk.language: dotnet
telemetry.sdk.name: opentelemetry
telemetry.sdk.version: <ANY>
scope_spans:
- instrumentation_scope:
attributes: {}
spans:
- name: GET /aspnetcoreapp/api/values/{id}
attributes:
aspnet_core.endpoint: 'HTTP: GET /api/values/{id}'
aspnet_core.route: /api/values/{id}
component: aspnet_core
http.host: localhost:8000
http.method: GET
http.status_code: "200"
http.url: http://localhost:8000/aspnetcoreapp/api/values/6
http.user_agent: Go-http-client/1.1
net.peer.ip: <ANY>
signalfx.tracing.library: dotnet-tracing
signalfx.tracing.version: <ANY>
splunk.zc.method: signalfx-dotnet-tracing-SIGNALFX_DOTNET_TRACING_VERSION
- instrumentation_scope:
attributes: {}
name: OpenTelemetry.Instrumentation.AspNetCore
version: <ANY>
spans:
- attributes:
http.request.method: GET
http.response.status_code: 200
http.route: /api/values/{id}
network.protocol.version: "1.1"
server.address: localhost
server.port: 8000
url.path: /aspnetcoreapp/api/values/6
url.scheme: http
user_agent.original: Go-http-client/1.1
name: GET /api/values/{id}
50 changes: 25 additions & 25 deletions tests/zeroconfig/windows/testdata/resource_traces/aspnetfx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ resource_spans:
deployment.environment: zc-iis-test
host.name: <ANY>
os.type: windows
process.pid: <ANY>
process.runtime.description: .NET Framework 4.8.4645.0
process.runtime.name: .NET Framework
process.runtime.version: "4.8"
pjanotti marked this conversation as resolved.
Show resolved Hide resolved
service.name: Default Web Site/aspnetfxapp
splunk.distro.version: SPLUNK_OTEL_DOTNET_VERSION
splunk.zc.method: splunk-otel-dotnet-vSPLUNK_OTEL_DOTNET_VERSION
telemetry.distro.name: splunk-otel-dotnet
telemetry.distro.version: SPLUNK_OTEL_DOTNET_VERSION
telemetry.sdk.language: dotnet
telemetry.sdk.name: opentelemetry
telemetry.sdk.version: <ANY>
scope_spans:
- instrumentation_scope:
attributes: {}
spans:
- name: GET /api/values/{id}
attributes:
http.host: localhost:8000
http.method: GET
http.status_code: "200"
http.url: http://localhost/aspnetfxapp/api/values/4
http.user_agent: Go-http-client/1.1
net.peer.ip: <ANY>
signalfx.tracing.library: dotnet-tracing
signalfx.tracing.version: <ANY>
splunk.zc.method: signalfx-dotnet-tracing-SIGNALFX_DOTNET_TRACING_VERSION
- name: GET /api/values/{id}
attributes:
aspnet.controller: values
aspnet.route: api/{controller}/{id}
http.host: localhost:8000
http.method: GET
http.status_code: "200"
http.url: http://localhost/aspnetfxapp/api/values/4
http.user_agent: Go-http-client/1.1
net.peer.ip: <ANY>
splunk.zc.method: signalfx-dotnet-tracing-SIGNALFX_DOTNET_TRACING_VERSION
- instrumentation_scope:
attributes: {}
name: OpenTelemetry.Instrumentation.AspNet.Telemetry
version: <ANY>
spans:
- attributes:
http.host: localhost
http.method: GET
http.route: api/{controller}/{id}
http.status_code: 200
http.target: /aspnetfxapp/api/values/4
http.url: http://localhost/aspnetfxapp/api/values/4
http.user_agent: Go-http-client/1.1
name: api/{controller}/{id}
Loading