Commit 4451fbe1 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch 'ali/send-environment-with-gitlab-standard' into 'master'

Snowplow: Send environment with standard context

See merge request gitlab-org/gitlab!51941
parents ab23d70d 7a68fded
......@@ -3,7 +3,7 @@
module Gitlab
module Tracking
class StandardContext
GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-1'.freeze
GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-2'.freeze
def initialize(namespace: nil, project: nil, **data)
@namespace = namespace
......@@ -15,6 +15,14 @@ module Gitlab
SnowplowTracker::SelfDescribingJson.new(GITLAB_STANDARD_SCHEMA_URL, to_h)
end
def environment
return 'production' if Gitlab.com_and_canary?
return 'staging' if Gitlab.staging?
'development'
end
private
def to_h
......
......@@ -10,9 +10,31 @@ RSpec.describe Gitlab::Tracking::StandardContext do
describe '#to_context' do
context 'with no arguments' do
it 'creates a Snowplow context with no data' do
snowplow_context.to_json[:data].each do |_, v|
expect(v).to be_nil
context 'environment' do
shared_examples 'contains environment' do |expected_environment|
it 'contains environment' do
expect(snowplow_context.to_json.dig(:data, :environment)).to eq(expected_environment)
end
end
context 'development or test' do
include_examples 'contains environment', 'development'
end
context 'staging' do
before do
allow(Gitlab).to receive(:staging?).and_return(true)
end
include_examples 'contains environment', 'staging'
end
context 'production' do
before do
allow(Gitlab).to receive(:com_and_canary?).and_return(true)
end
include_examples 'contains environment', 'production'
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment