Skip to content
Merged
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
21 changes: 21 additions & 0 deletions model/ccotel_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func NewBashCCOtelEnvService() CCOtelEnvService {
"export OTEL_LOGS_EXPORTER=otlp",
"export OTEL_EXPORTER_OTLP_PROTOCOL=grpc",
"export OTEL_EXPORTER_OTLP_ENDPOINT=" + ccOtelEndpoint,
"export OTEL_METRIC_EXPORT_INTERVAL=10000",
"export OTEL_LOGS_EXPORT_INTERVAL=5000",
"export OTEL_LOG_USER_PROMPTS=1",
"export OTEL_METRICS_INCLUDE_SESSION_ID=true",
"export OTEL_METRICS_INCLUDE_VERSION=true",
"export OTEL_METRICS_INCLUDE_ACCOUNT_UUID=true",
"export OTEL_RESOURCE_ATTRIBUTES=\"user.name=$(whoami),machine.name=$(hostname),team.id=shelltime\"",
Comment on lines +118 to +124
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

These new OTEL configuration values are hardcoded and duplicated across the NewBashCCOtelEnvService, NewZshCCOtelEnvService, and NewFishCCOtelEnvService functions. This code duplication, especially between the bash and zsh implementations which are identical, can make future updates error-prone and tedious.

To improve maintainability, I recommend defining these values as constants at the package level. This centralizes the configuration, reduces the risk of inconsistencies, and makes the code easier to read and manage.

For example, you could define constants for the new settings:

const (
    // ... existing constants
    otelMetricExportInterval = "10000"
    otelLogsExportInterval   = "5000"
    otelLogUserPrompts       = "1"
    otelMetricsIncludeSessID = "true"
    // ... and so on
)

Then, these constants can be used to construct the envLines slices for each shell. While a larger refactoring to eliminate the duplicated envLines slices might be out of scope for this PR, introducing constants for these new values would be a valuable improvement.

ccOtelMarkerEnd,
}

Expand Down Expand Up @@ -200,6 +207,13 @@ func NewZshCCOtelEnvService() CCOtelEnvService {
"export OTEL_LOGS_EXPORTER=otlp",
"export OTEL_EXPORTER_OTLP_PROTOCOL=grpc",
"export OTEL_EXPORTER_OTLP_ENDPOINT=" + ccOtelEndpoint,
"export OTEL_METRIC_EXPORT_INTERVAL=10000",
"export OTEL_LOGS_EXPORT_INTERVAL=5000",
"export OTEL_LOG_USER_PROMPTS=1",
"export OTEL_METRICS_INCLUDE_SESSION_ID=true",
"export OTEL_METRICS_INCLUDE_VERSION=true",
"export OTEL_METRICS_INCLUDE_ACCOUNT_UUID=true",
"export OTEL_RESOURCE_ATTRIBUTES=\"user.name=$(whoami),machine.name=$(hostname),team.id=shelltime\"",
ccOtelMarkerEnd,
}

Expand Down Expand Up @@ -282,6 +296,13 @@ func NewFishCCOtelEnvService() CCOtelEnvService {
"set -gx OTEL_LOGS_EXPORTER otlp",
"set -gx OTEL_EXPORTER_OTLP_PROTOCOL grpc",
"set -gx OTEL_EXPORTER_OTLP_ENDPOINT " + ccOtelEndpoint,
"set -gx OTEL_METRIC_EXPORT_INTERVAL 10000",
"set -gx OTEL_LOGS_EXPORT_INTERVAL 5000",
"set -gx OTEL_LOG_USER_PROMPTS 1",
"set -gx OTEL_METRICS_INCLUDE_SESSION_ID true",
"set -gx OTEL_METRICS_INCLUDE_VERSION true",
"set -gx OTEL_METRICS_INCLUDE_ACCOUNT_UUID true",
"set -gx OTEL_RESOURCE_ATTRIBUTES \"user.name=$(whoami),machine.name=$(hostname),team.id=shelltime\"",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For fish shell, the idiomatic syntax for command substitution is (command) rather than $(command). While $(command) is supported in modern versions of fish for POSIX compatibility, using the native (command) syntax is preferred. It ensures better compatibility with all fish versions and aligns with the shell's design principles.

Suggested change
"set -gx OTEL_RESOURCE_ATTRIBUTES \"user.name=$(whoami),machine.name=$(hostname),team.id=shelltime\"",
"set -gx OTEL_RESOURCE_ATTRIBUTES \"user.name=(whoami),machine.name=(hostname),team.id=shelltime\""

ccOtelMarkerEnd,
}

Expand Down