|
| 1 | +# Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +# license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright |
| 4 | +# ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +# the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +if ENV['TEST_WITH_OTEL'] == 'true' |
| 19 | + ELASTICSEARCH_URL = ENV['TEST_ES_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}" |
| 20 | + raise URI::InvalidURIError unless ELASTICSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/ |
| 21 | + |
| 22 | + require 'spec_helper' |
| 23 | + |
| 24 | + context 'OpenTelemetry' do |
| 25 | + let(:exporter) { EXPORTER } |
| 26 | + before { exporter.reset } |
| 27 | + after { exporter.reset } |
| 28 | + let(:span) { exporter.finished_spans[0] } |
| 29 | + |
| 30 | + let(:client) do |
| 31 | + Elasticsearch::Client.new( |
| 32 | + host: ELASTICSEARCH_URL, |
| 33 | + user: 'elastic', |
| 34 | + password: 'changeme' |
| 35 | + ) |
| 36 | + end |
| 37 | + |
| 38 | + after do |
| 39 | + client.delete(index: 'myindex', id: 1); rescue |
| 40 | + end |
| 41 | + |
| 42 | + context 'when a request is instrumented' do |
| 43 | + it 'sets the span name to the endpoint id' do |
| 44 | + client.search(body: { query: { match: {a: 1} } }) |
| 45 | + expect(span.name).to eq 'search' |
| 46 | + end |
| 47 | + |
| 48 | + it 'sets the path parts' do |
| 49 | + client.index(index: 'myindex', id: 1, body: { title: 'Test' }) |
| 50 | + expect(span.attributes['db.elasticsearch.path_parts.index']).to eq 'myindex' |
| 51 | + expect(span.attributes['db.elasticsearch.path_parts.id']).to eq 1 |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | +end |
0 commit comments