diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index dc53f4183..2c2bf8613 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-elixir@v1 + - uses: erlef/setup-elixir@v1 with: otp-version: '23.1' elixir-version: '1.11.1' @@ -22,7 +22,7 @@ jobs: with: path: | apps/opentelemetry_api/deps - key: v2-${{ hashFiles('apps/opentelemetry_api/mix.lock') }} + key: v3-${{ hashFiles('apps/opentelemetry_api/mix.lock') }} - run: mix format --check-formatted - run: mix deps.get working-directory: apps/opentelemetry_api/ @@ -42,7 +42,7 @@ jobs: OTEL_TRACES_EXPORTER: "none" steps: - uses: actions/checkout@v2 - - uses: actions/setup-elixir@v1 + - uses: erlef/setup-elixir@v1 with: otp-version: ${{ matrix.otp_version }} elixir-version: ${{ matrix.elixir }} @@ -67,7 +67,7 @@ jobs: working-directory: apps/opentelemetry_api/ steps: - uses: actions/checkout@v2 - - uses: actions/setup-elixir@v1 + - uses: erlef/setup-elixir@v1 with: otp-version: ${{ matrix.otp_version }} elixir-version: ${{ matrix.elixir }} @@ -77,7 +77,7 @@ jobs: path: | apps/opentelemetry_api/deps apps/opentelemetry_api/_build - key: ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ matrix.elixir }}-v2-${{ hashFiles(format('{0}{1}', github.workspace, '/apps/opentelemetry_api/mix.lock')) }} + key: ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ matrix.elixir }}-v3-${{ hashFiles(format('{0}{1}', github.workspace, '/apps/opentelemetry_api/mix.lock')) }} restore-keys: | ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ matrix.elixir }}- - run: mix deps.get @@ -107,7 +107,7 @@ jobs: working-directory: apps/opentelemetry_api/ steps: - uses: actions/checkout@v2 - - uses: actions/setup-elixir@v1 + - uses: erlef/setup-elixir@v1 with: otp-version: ${{ matrix.otp_version }} elixir-version: ${{ matrix.elixir }} @@ -117,7 +117,7 @@ jobs: path: | apps/opentelemetry_api/deps apps/opentelemetry_api/_build - key: ${{ runner.os }}-dialyzer-${{ matrix.otp_version }}-${{ matrix.elixir }}-v2-${{ hashFiles('apps/opentelemetry_api/mix.lock') }} + key: ${{ runner.os }}-dialyzer-${{ matrix.otp_version }}-${{ matrix.elixir }}-v3-${{ hashFiles('apps/opentelemetry_api/mix.lock') }} restore-keys: | ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ matrix.elixir }}- - run: mix deps.get diff --git a/.github/workflows/erlang.yml b/.github/workflows/erlang.yml index 15f11c03e..221024219 100644 --- a/.github/workflows/erlang.yml +++ b/.github/workflows/erlang.yml @@ -23,17 +23,18 @@ jobs: - uses: actions/checkout@v2 - name: Run Collector run: docker-compose up -d - - uses: gleam-lang/setup-erlang@v1.0.0 + - uses: erlef/setup-elixir@v1 with: otp-version: ${{ matrix.otp_version }} + elixir-version: '1.11.1' - uses: actions/cache@v2 name: Cache with: path: | _build - key: ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ hashFiles(format('rebar.lock')) }}-1 + key: ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ hashFiles(format('rebar.lock')) }}-2 restore-keys: | - ${{ runner.os }}-build-${{ matrix.otp_version }}-1- + ${{ runner.os }}-build-${{ matrix.otp_version }}-2- - name: Compile run: rebar3 compile - name: EUnit tests @@ -72,17 +73,18 @@ jobs: os: [ubuntu-latest] steps: - uses: actions/checkout@v2 - - uses: gleam-lang/setup-erlang@v1.0.0 + - uses: erlef/setup-elixir@v1 with: otp-version: ${{ matrix.otp_version }} + elixir-version: '1.11.1' - uses: actions/cache@v2 name: Cache with: path: | _build - key: ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ hashFiles('rebar.lock') }}-1 + key: ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ hashFiles('rebar.lock') }}-2 restore-keys: | - ${{ runner.os }}-dialyzer-${{ matrix.otp_version }}-1- + ${{ runner.os }}-dialyzer-${{ matrix.otp_version }}-2- - name: Compile run: rebar3 compile - name: Dialyzer diff --git a/apps/opentelemetry/src/opentelemetry.app.src b/apps/opentelemetry/src/opentelemetry.app.src index 8e1c7d919..ff16c0974 100644 --- a/apps/opentelemetry/src/opentelemetry.app.src +++ b/apps/opentelemetry/src/opentelemetry.app.src @@ -1,5 +1,5 @@ {application, opentelemetry, - [{description, "OpenTelemetry stats collection and distributed tracing framework for Erlang"}, + [{description, "Implementation of stable OpenTelemetry signals"}, {vsn, "git"}, {registered, []}, {mod, {opentelemetry_app, []}}, diff --git a/apps/opentelemetry/src/opentelemetry_app.erl b/apps/opentelemetry/src/opentelemetry_app.erl index e29df9672..e883de96e 100644 --- a/apps/opentelemetry/src/opentelemetry_app.erl +++ b/apps/opentelemetry/src/opentelemetry_app.erl @@ -38,7 +38,6 @@ prep_stop(_State) -> %% This is to ensure no crashes if the sdk isn't the last %% thing to shutdown or if the opentelemetry application crashed. opentelemetry:set_default_tracer({otel_tracer_noop, []}), - opentelemetry:set_default_meter({otel_meter_noop, []}), ok. stop(_State) -> diff --git a/apps/opentelemetry/src/opentelemetry_sup.erl b/apps/opentelemetry/src/opentelemetry_sup.erl index 595b4e081..1cceb3969 100644 --- a/apps/opentelemetry/src/opentelemetry_sup.erl +++ b/apps/opentelemetry/src/opentelemetry_sup.erl @@ -48,14 +48,6 @@ init([Opts]) -> type => worker, modules => [otel_tracer_provider, otel_tracer_server]}, - %% - MetricSup = #{id => otel_metric_sup, - start => {otel_metric_sup, start_link, [Opts]}, - restart => permanent, - shutdown => 5000, - type => supervisor, - modules => [otel_metric_sup]}, - Processors = proplists:get_value(processors, Opts, []), BatchProcessorOpts = proplists:get_value(otel_batch_processor, Processors, #{}), BatchProcessorOpts1 = case proplists:get_value(traces_exporter, Opts) of @@ -81,6 +73,6 @@ init([Opts]) -> %% `TracerServer' *must* start before the `BatchProcessor' %% `BatchProcessor' relies on getting the `Resource' from %% the `TracerServer' process - ChildSpecs = [Detectors, MetricSup, TracerServer, BatchProcessor, SpanSup], + ChildSpecs = [Detectors, TracerServer, BatchProcessor, SpanSup], {ok, {SupFlags, ChildSpecs}}. diff --git a/apps/opentelemetry_api/VERSION b/apps/opentelemetry_api/VERSION index a918a2aa1..9c218192d 100644 --- a/apps/opentelemetry_api/VERSION +++ b/apps/opentelemetry_api/VERSION @@ -1 +1 @@ -0.6.0 +1.0.0-rc.1 diff --git a/apps/opentelemetry_api/lib/open_telemetry.ex b/apps/opentelemetry_api/lib/open_telemetry.ex index 712bf7b28..78f9d7fea 100644 --- a/apps/opentelemetry_api/lib/open_telemetry.ex +++ b/apps/opentelemetry_api/lib/open_telemetry.ex @@ -130,9 +130,6 @@ defmodule OpenTelemetry do defdelegate register_tracer(name, vsn), to: :opentelemetry defdelegate set_default_tracer(t), to: :opentelemetry - @spec register_application_meter(atom()) :: boolean() - defdelegate register_application_meter(name), to: :opentelemetry - # Helpers to build OpenTelemetry structured types @doc """ diff --git a/apps/opentelemetry_api/src/opentelemetry.erl b/apps/opentelemetry_api/src/opentelemetry.erl index d191c1678..8c64927c4 100644 --- a/apps/opentelemetry_api/src/opentelemetry.erl +++ b/apps/opentelemetry_api/src/opentelemetry.erl @@ -30,16 +30,10 @@ -export([set_default_tracer/1, set_tracer/2, - set_meter/2, - set_default_meter/1, register_tracer/2, register_application_tracer/1, - register_meter/2, - register_application_meter/1, get_tracer/0, get_tracer/1, - get_meter/0, - get_meter/1, set_text_map_extractors/1, get_text_map_extractors/0, set_text_map_injectors/1, @@ -55,6 +49,8 @@ event/3, events/1, status/2, + verify_and_set_term/3, + verify_and_set_term/4, generate_trace_id/0, generate_span_id/0]). @@ -62,7 +58,6 @@ -include_lib("kernel/include/logger.hrl"). -export_type([tracer/0, - meter/0, trace_id/0, span_id/0, trace_flags/0, @@ -86,7 +81,6 @@ text_map/0]). -type tracer() :: {module(), term()}. --type meter() :: {module(), term()}. -type trace_id() :: non_neg_integer(). -type span_id() :: non_neg_integer(). @@ -137,14 +131,6 @@ set_default_tracer(Tracer) -> set_tracer(Name, Tracer) -> verify_and_set_term(Tracer, Name, otel_tracer). --spec set_default_meter(meter()) -> boolean(). -set_default_meter(Meter) -> - verify_and_set_term(Meter, default_meter, otel_meter). - --spec set_meter(atom(), meter()) -> boolean(). -set_meter(Name, Meter) -> - verify_and_set_term(Meter, Name, otel_meter). - -spec register_tracer(atom(), string()) -> boolean(). register_tracer(Name, Vsn) -> otel_tracer_provider:register_tracer(Name, Vsn). @@ -153,14 +139,6 @@ register_tracer(Name, Vsn) -> register_application_tracer(Name) -> otel_tracer_provider:register_application_tracer(Name). --spec register_meter(atom(), string()) -> boolean(). -register_meter(Name, Vsn) -> - otel_meter_provider:register_meter(Name, Vsn). - --spec register_application_meter(atom()) -> boolean(). -register_application_meter(Name) -> - otel_meter_provider:register_application_meter(Name). - -spec get_tracer() -> tracer(). get_tracer() -> persistent_term:get({?MODULE, default_tracer}, {otel_tracer_noop, []}). @@ -169,14 +147,6 @@ get_tracer() -> get_tracer(Name) -> persistent_term:get({?MODULE, Name}, get_tracer()). --spec get_meter() -> meter(). -get_meter() -> - persistent_term:get({?MODULE, default_meter}, {otel_meter_noop, []}). - --spec get_meter(atom()) -> meter(). -get_meter(Name) -> - persistent_term:get({?MODULE, Name}, get_meter()). - set_text_map_extractors(List) when is_list(List) -> persistent_term:put({?MODULE, text_map_extractors}, List); set_text_map_extractors(_) -> @@ -360,9 +330,12 @@ uniform(X) -> -spec verify_and_set_term(module() | {module(), term()}, term(), atom()) -> boolean(). verify_and_set_term(Module, TermKey, Behaviour) -> + verify_and_set_term(?MODULE, Module, TermKey, Behaviour). + +verify_and_set_term(AppKey, Module, TermKey, Behaviour) -> case verify_module_exists(Module) of true -> - persistent_term:put({?MODULE, TermKey}, Module), + persistent_term:put({AppKey, TermKey}, Module), true; false -> ?LOG_WARNING("Module ~p does not exist. " diff --git a/apps/opentelemetry_api_experimental/.gitignore b/apps/opentelemetry_api_experimental/.gitignore new file mode 100644 index 000000000..f1c455451 --- /dev/null +++ b/apps/opentelemetry_api_experimental/.gitignore @@ -0,0 +1,19 @@ +.rebar3 +_* +.eunit +*.o +*.beam +*.plt +*.swp +*.swo +.erlang.cookie +ebin +log +erl_crash.dump +.rebar +logs +_build +.idea +*.iml +rebar3.crashdump +*~ diff --git a/apps/opentelemetry_api_experimental/LICENSE b/apps/opentelemetry_api_experimental/LICENSE new file mode 100644 index 000000000..a558eb79b --- /dev/null +++ b/apps/opentelemetry_api_experimental/LICENSE @@ -0,0 +1,191 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright 2021, Tristan Sloughter . + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/apps/opentelemetry_api_experimental/README.md b/apps/opentelemetry_api_experimental/README.md new file mode 100644 index 000000000..0d25c25a3 --- /dev/null +++ b/apps/opentelemetry_api_experimental/README.md @@ -0,0 +1,9 @@ +opentelemetry_api_experimental +===== + +An OTP library + +Build +----- + + $ rebar3 compile diff --git a/apps/opentelemetry_api_experimental/VERSION b/apps/opentelemetry_api_experimental/VERSION new file mode 100644 index 000000000..6e8bf73aa --- /dev/null +++ b/apps/opentelemetry_api_experimental/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/apps/opentelemetry_api/include/otel_meter.hrl b/apps/opentelemetry_api_experimental/include/otel_meter.hrl similarity index 96% rename from apps/opentelemetry_api/include/otel_meter.hrl rename to apps/opentelemetry_api_experimental/include/otel_meter.hrl index f917146cd..55da51a0b 100644 --- a/apps/opentelemetry_api/include/otel_meter.hrl +++ b/apps/opentelemetry_api_experimental/include/otel_meter.hrl @@ -1,7 +1,7 @@ %% macros for meters %% register a meter for an application with opentelemetry:register_application_meter(AppName) --define(otel_current_meter, opentelemetry:get_meter(?MODULE)). +-define(otel_current_meter, opentelemetry_experimental:get_meter(?MODULE)). -define(otel_new_counter(Meter, Name, Opts), otel_counter:new(?otel_current_meter, Name, Opts)). diff --git a/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental.ex new file mode 100644 index 000000000..992cccc43 --- /dev/null +++ b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental.ex @@ -0,0 +1,7 @@ +defmodule OpenTelemetryExperimental do + @moduledoc """ + """ + + @spec register_application_meter(atom()) :: boolean() + defdelegate register_application_meter(name), to: :opentelemetry_experimental +end diff --git a/apps/opentelemetry_api/lib/open_telemetry/counter.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/counter.ex similarity index 100% rename from apps/opentelemetry_api/lib/open_telemetry/counter.ex rename to apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/counter.ex diff --git a/apps/opentelemetry_api/lib/open_telemetry/meter.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/meter.ex similarity index 100% rename from apps/opentelemetry_api/lib/open_telemetry/meter.ex rename to apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/meter.ex diff --git a/apps/opentelemetry_api/lib/open_telemetry/sum_observer.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/sum_observer.ex similarity index 100% rename from apps/opentelemetry_api/lib/open_telemetry/sum_observer.ex rename to apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/sum_observer.ex diff --git a/apps/opentelemetry_api/lib/open_telemetry/updown_counter.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/updown_counter.ex similarity index 100% rename from apps/opentelemetry_api/lib/open_telemetry/updown_counter.ex rename to apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/updown_counter.ex diff --git a/apps/opentelemetry_api/lib/open_telemetry/updown_sum_observer.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/updown_sum_observer.ex similarity index 100% rename from apps/opentelemetry_api/lib/open_telemetry/updown_sum_observer.ex rename to apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/updown_sum_observer.ex diff --git a/apps/opentelemetry_api/lib/open_telemetry/value_observer.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/value_observer.ex similarity index 100% rename from apps/opentelemetry_api/lib/open_telemetry/value_observer.ex rename to apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/value_observer.ex diff --git a/apps/opentelemetry_api/lib/open_telemetry/value_recorder.ex b/apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/value_recorder.ex similarity index 100% rename from apps/opentelemetry_api/lib/open_telemetry/value_recorder.ex rename to apps/opentelemetry_api_experimental/lib/opentelemetry_api_experimental/value_recorder.ex diff --git a/apps/opentelemetry_api_experimental/mix.exs b/apps/opentelemetry_api_experimental/mix.exs new file mode 100644 index 000000000..4ab5126c4 --- /dev/null +++ b/apps/opentelemetry_api_experimental/mix.exs @@ -0,0 +1,95 @@ +defmodule OpenTelemetry.MixProject do + use Mix.Project + + def project do + {app, desc} = load_app() + config = load_config() + + [ + app: app, + version: version(Keyword.fetch!(desc, :vsn)), + description: to_string(Keyword.fetch!(desc, :description)), + elixir: "~> 1.8", + start_permanent: Mix.env() == :prod, + # We should never have dependencies + deps: deps(Keyword.fetch!(config, :deps)), + # Docs + name: "OpenTelemetry Experimental API", + # source_url: "https://github.com/USER/PROJECT", + # homepage_url: "http://YOUR_PROJECT_HOMEPAGE", + test_coverage: [tool: :covertool], + docs: [ + markdown_processor: ExDoc.Markdown.Cmark, + main: "OpenTelemetry Experimental", + # logo: "path/to/logo.png", + extras: erlang_docs() + ], + aliases: [ + # when build docs first build edocs with rebar3 + docs: ["cmd rebar3 edoc", "docs"] + ], + package: package() + ] + end + + defp version(version) when is_list(version) do + List.to_string(version) + end + + defp version({:file, path}) do + path + |> File.read!() + |> String.trim() + end + + # Run "mix help compile.app" to learn about applications. + def application, do: [] + + defp deps(rebar) do + rebar + |> Enum.map(fn + {dep, version} -> {dep, to_string(version)} + dep when is_atom(dep) -> {dep, ">= 0.0.0"} + end) + |> Enum.concat([ + {:cmark, "~> 0.7", only: :dev, runtime: false}, + {:ex_doc, "0.21.0", only: :dev, runtime: false}, + {:dialyxir, "~> 1.0", only: [:dev], runtime: false}, + {:covertool, ">= 0.0.0", only: :test} + ]) + end + + defp package() do + [ + description: "OpenTelemetry Experimental API", + build_tools: ["rebar3", "mix"], + files: ~w(lib mix.exs README.md LICENSE rebar.config VERSION include src), + licenses: ["Apache-2.0"], + links: %{ + "GitHub" => "https://github.com/open-telemetry/opentelemetry-erlang", + "OpenTelemetry.io" => "https://opentelemetry.io" + } + ] + end + + def erlang_docs() do + files = + for file <- Path.wildcard("edoc/*.md"), + file != "edoc/README.md", + do: {String.to_atom(file), [title: Path.basename(file, ".md")]} + + [{:"README.md", [title: "Overview"]} | files] + end + + defp load_config do + {:ok, config} = :file.consult('rebar.config') + + config + end + + defp load_app do + {:ok, [{:application, name, desc}]} = :file.consult('src/opentelemetry_api_experimental.app.src') + + {name, desc} + end +end diff --git a/apps/opentelemetry_api_experimental/rebar.config b/apps/opentelemetry_api_experimental/rebar.config new file mode 100644 index 000000000..f618f3e40 --- /dev/null +++ b/apps/opentelemetry_api_experimental/rebar.config @@ -0,0 +1,2 @@ +{erl_opts, [debug_info]}. +{deps, []}. \ No newline at end of file diff --git a/apps/opentelemetry_api_experimental/src/opentelemetry_api_experimental.app.src b/apps/opentelemetry_api_experimental/src/opentelemetry_api_experimental.app.src new file mode 100644 index 000000000..b939226bb --- /dev/null +++ b/apps/opentelemetry_api_experimental/src/opentelemetry_api_experimental.app.src @@ -0,0 +1,14 @@ +{application, opentelemetry_api_experimental, + [{description, "API for unstable OpenTelemetry signals"}, + {vsn, "0.1.0"}, + {registered, []}, + {applications, + [kernel, + stdlib + ]}, + {env,[]}, + {modules, []}, + + {licenses, ["Apache 2.0"]}, + {links, [{"GitHub", "https://github.com/open-telemetry/opentelemetry-erlang"}]} + ]}. diff --git a/apps/opentelemetry_api_experimental/src/opentelemetry_api_experimental.erl b/apps/opentelemetry_api_experimental/src/opentelemetry_api_experimental.erl new file mode 100644 index 000000000..b4df5f94e --- /dev/null +++ b/apps/opentelemetry_api_experimental/src/opentelemetry_api_experimental.erl @@ -0,0 +1,3 @@ +-module(opentelemetry_api_experimental). + +-export([]). diff --git a/apps/opentelemetry_api_experimental/src/opentelemetry_experimental.erl b/apps/opentelemetry_api_experimental/src/opentelemetry_experimental.erl new file mode 100644 index 000000000..9e7afd0d4 --- /dev/null +++ b/apps/opentelemetry_api_experimental/src/opentelemetry_experimental.erl @@ -0,0 +1,55 @@ +%%%------------------------------------------------------------------------ +%% Copyright 2019, OpenTelemetry Authors +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% @doc +%% @end +%%%------------------------------------------------------------------------- +-module(opentelemetry_experimental). + +-export([set_meter/2, + set_default_meter/1, + get_meter/0, + get_meter/1, + register_meter/2, + register_application_meter/1]). + +-include_lib("kernel/include/logger.hrl"). + +-export_type([meter/0]). + +-type meter() :: {module(), term()}. + +-spec set_default_meter(meter()) -> boolean(). +set_default_meter(Meter) -> + opentelemetry:verify_and_set_term(?MODULE, Meter, default_meter, otel_meter). + +-spec set_meter(atom(), meter()) -> boolean(). +set_meter(Name, Meter) -> + opentelemetry:verify_and_set_term(?MODULE, Meter, Name, otel_meter). + +-spec register_meter(atom(), string()) -> boolean(). +register_meter(Name, Vsn) -> + otel_meter_provider:register_meter(Name, Vsn). + +-spec register_application_meter(atom()) -> boolean(). +register_application_meter(Name) -> + otel_meter_provider:register_application_meter(Name). + +-spec get_meter() -> meter(). +get_meter() -> + persistent_term:get({?MODULE, default_meter}, {otel_meter_noop, []}). + +-spec get_meter(atom()) -> meter(). +get_meter(Name) -> + persistent_term:get({?MODULE, Name}, get_meter()). diff --git a/apps/opentelemetry_api/src/otel_counter.erl b/apps/opentelemetry_api_experimental/src/otel_counter.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_counter.erl rename to apps/opentelemetry_api_experimental/src/otel_counter.erl diff --git a/apps/opentelemetry_api/src/otel_instrument.erl b/apps/opentelemetry_api_experimental/src/otel_instrument.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_instrument.erl rename to apps/opentelemetry_api_experimental/src/otel_instrument.erl diff --git a/apps/opentelemetry_api/src/otel_meter.erl b/apps/opentelemetry_api_experimental/src/otel_meter.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_meter.erl rename to apps/opentelemetry_api_experimental/src/otel_meter.erl diff --git a/apps/opentelemetry_api/src/otel_meter_noop.erl b/apps/opentelemetry_api_experimental/src/otel_meter_noop.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_meter_noop.erl rename to apps/opentelemetry_api_experimental/src/otel_meter_noop.erl diff --git a/apps/opentelemetry_api/src/otel_meter_provider.erl b/apps/opentelemetry_api_experimental/src/otel_meter_provider.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_meter_provider.erl rename to apps/opentelemetry_api_experimental/src/otel_meter_provider.erl diff --git a/apps/opentelemetry_api/src/otel_observer.erl b/apps/opentelemetry_api_experimental/src/otel_observer.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_observer.erl rename to apps/opentelemetry_api_experimental/src/otel_observer.erl diff --git a/apps/opentelemetry_api/src/otel_sum_observer.erl b/apps/opentelemetry_api_experimental/src/otel_sum_observer.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_sum_observer.erl rename to apps/opentelemetry_api_experimental/src/otel_sum_observer.erl diff --git a/apps/opentelemetry_api/src/otel_updown_counter.erl b/apps/opentelemetry_api_experimental/src/otel_updown_counter.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_updown_counter.erl rename to apps/opentelemetry_api_experimental/src/otel_updown_counter.erl diff --git a/apps/opentelemetry_api/src/otel_updown_sum_observer.erl b/apps/opentelemetry_api_experimental/src/otel_updown_sum_observer.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_updown_sum_observer.erl rename to apps/opentelemetry_api_experimental/src/otel_updown_sum_observer.erl diff --git a/apps/opentelemetry_api/src/otel_value_observer.erl b/apps/opentelemetry_api_experimental/src/otel_value_observer.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_value_observer.erl rename to apps/opentelemetry_api_experimental/src/otel_value_observer.erl diff --git a/apps/opentelemetry_api/src/otel_value_recorder.erl b/apps/opentelemetry_api_experimental/src/otel_value_recorder.erl similarity index 100% rename from apps/opentelemetry_api/src/otel_value_recorder.erl rename to apps/opentelemetry_api_experimental/src/otel_value_recorder.erl diff --git a/apps/opentelemetry_api/test/otel_metrics_SUITE.erl b/apps/opentelemetry_api_experimental/test/otel_metrics_SUITE.erl similarity index 92% rename from apps/opentelemetry_api/test/otel_metrics_SUITE.erl rename to apps/opentelemetry_api_experimental/test/otel_metrics_SUITE.erl index 67c57d28d..c63897827 100644 --- a/apps/opentelemetry_api/test/otel_metrics_SUITE.erl +++ b/apps/opentelemetry_api_experimental/test/otel_metrics_SUITE.erl @@ -4,8 +4,7 @@ -include_lib("stdlib/include/assert.hrl"). -include_lib("common_test/include/ct.hrl"). - --include("opentelemetry.hrl"). +-include_lib("opentelemetry_api/include/opentelemetry.hrl"). -include("otel_meter.hrl"). all() -> @@ -19,7 +18,7 @@ end_per_suite(_Config) -> ok. noop_metrics(_Config) -> - Meter = opentelemetry:get_meter(), + Meter = opentelemetry_experimental:get_meter(), ?assertMatch({otel_meter_noop, _}, Meter), ?assert(otel_counter:new(Meter, <<"noop-measure-1">>, #{description => <<"some description">>})), diff --git a/apps/opentelemetry_experimental/.gitignore b/apps/opentelemetry_experimental/.gitignore new file mode 100644 index 000000000..f1c455451 --- /dev/null +++ b/apps/opentelemetry_experimental/.gitignore @@ -0,0 +1,19 @@ +.rebar3 +_* +.eunit +*.o +*.beam +*.plt +*.swp +*.swo +.erlang.cookie +ebin +log +erl_crash.dump +.rebar +logs +_build +.idea +*.iml +rebar3.crashdump +*~ diff --git a/apps/opentelemetry_experimental/LICENSE b/apps/opentelemetry_experimental/LICENSE new file mode 100644 index 000000000..a558eb79b --- /dev/null +++ b/apps/opentelemetry_experimental/LICENSE @@ -0,0 +1,191 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + Copyright 2021, Tristan Sloughter . + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/apps/opentelemetry_experimental/README.md b/apps/opentelemetry_experimental/README.md new file mode 100644 index 000000000..18bdb92d9 --- /dev/null +++ b/apps/opentelemetry_experimental/README.md @@ -0,0 +1,9 @@ +opentelemetry_experimental +===== + +An OTP application + +Build +----- + + $ rebar3 compile diff --git a/apps/opentelemetry_experimental/rebar.config b/apps/opentelemetry_experimental/rebar.config new file mode 100644 index 000000000..b455279f9 --- /dev/null +++ b/apps/opentelemetry_experimental/rebar.config @@ -0,0 +1,7 @@ +{erl_opts, [debug_info]}. +{deps, []}. + +{shell, [ + % {config, "config/sys.config"}, + {apps, [opentelemetry_experimental]} +]}. diff --git a/apps/opentelemetry_experimental/src/opentelemetry_experimental.app.src b/apps/opentelemetry_experimental/src/opentelemetry_experimental.app.src new file mode 100644 index 000000000..795430c19 --- /dev/null +++ b/apps/opentelemetry_experimental/src/opentelemetry_experimental.app.src @@ -0,0 +1,17 @@ +{application, opentelemetry_experimental, + [{description, "Implementation of unstable OpenTelemetry signals"}, + {vsn, "0.1.0"}, + {registered, []}, + {mod, {opentelemetry_experimental_app, []}}, + {applications, + [kernel, + stdlib, + opentelemetry_api_experimental, + opentelemetry + ]}, + {env,[]}, + {modules, []}, + + {licenses, ["Apache 2.0"]}, + {links, [{"GitHub", "https://github.com/open-telemetry/opentelemetry-erlang"}]} + ]}. diff --git a/apps/opentelemetry_experimental/src/opentelemetry_experimental_app.erl b/apps/opentelemetry_experimental/src/opentelemetry_experimental_app.erl new file mode 100644 index 000000000..ef69f683b --- /dev/null +++ b/apps/opentelemetry_experimental/src/opentelemetry_experimental_app.erl @@ -0,0 +1,31 @@ +%%%------------------------------------------------------------------- +%% @doc opentelemetry_experimental public API +%% @end +%%%------------------------------------------------------------------- + +-module(opentelemetry_experimental_app). + +-behaviour(application). + +-export([start/2, + prep_stop/1, + stop/1]). + +start(_StartType, _StartArgs) -> + Opts = otel_configuration:merge_with_os( + application:get_all_env(opentelemetry_experimental)), + + opentelemetry_experimental_sup:start_link(Opts). + +%% called before the supervision tree is shutdown. +prep_stop(_State) -> + %% on application stop set meter to the noop implementation. + %% This is to ensure no crashes if the sdk isn't the last + %% thing to shutdown or if the opentelemetry application crashed. + opentelemetry_experimental:set_default_meter({otel_meter_noop, []}), + ok. + +stop(_State) -> + ok. + +%% internal functions diff --git a/apps/opentelemetry_experimental/src/opentelemetry_experimental_sup.erl b/apps/opentelemetry_experimental/src/opentelemetry_experimental_sup.erl new file mode 100644 index 000000000..30e5d2d54 --- /dev/null +++ b/apps/opentelemetry_experimental/src/opentelemetry_experimental_sup.erl @@ -0,0 +1,35 @@ +%%%------------------------------------------------------------------- +%% @doc opentelemetry_experimental top level supervisor. +%% @end +%%%------------------------------------------------------------------- + +-module(opentelemetry_experimental_sup). + +-behaviour(supervisor). + +-export([start_link/1]). + +-export([init/1]). + +-define(SERVER, ?MODULE). + +start_link(Opts) -> + supervisor:start_link({local, ?SERVER}, ?MODULE, [Opts]). + +init([Opts]) -> + SupFlags = #{strategy => one_for_one, + intensity => 1, + period => 5}, + + %% + MetricSup = #{id => otel_metric_sup, + start => {otel_metric_sup, start_link, [Opts]}, + restart => permanent, + shutdown => 5000, + type => supervisor, + modules => [otel_metric_sup]}, + + ChildSpecs = [MetricSup], + {ok, {SupFlags, ChildSpecs}}. + +%% internal functions diff --git a/apps/opentelemetry/src/otel_meter.hrl b/apps/opentelemetry_experimental/src/otel_meter.hrl similarity index 100% rename from apps/opentelemetry/src/otel_meter.hrl rename to apps/opentelemetry_experimental/src/otel_meter.hrl diff --git a/apps/opentelemetry/src/otel_meter_default.erl b/apps/opentelemetry_experimental/src/otel_meter_default.erl similarity index 100% rename from apps/opentelemetry/src/otel_meter_default.erl rename to apps/opentelemetry_experimental/src/otel_meter_default.erl diff --git a/apps/opentelemetry/src/otel_meter_server.erl b/apps/opentelemetry_experimental/src/otel_meter_server.erl similarity index 79% rename from apps/opentelemetry/src/otel_meter_server.erl rename to apps/opentelemetry_experimental/src/otel_meter_server.erl index 18ce84d7b..fc60209eb 100644 --- a/apps/opentelemetry/src/otel_meter_server.erl +++ b/apps/opentelemetry_experimental/src/otel_meter_server.erl @@ -24,7 +24,7 @@ -include_lib("opentelemetry_api/include/opentelemetry.hrl"). -include("otel_meter.hrl"). --include("otel_span.hrl"). +-include_lib("opentelemetry/include/otel_span.hrl"). -record(state, {meter :: meter(), deny_list :: [atom() | {atom(), string()}]}). @@ -33,7 +33,7 @@ init(Opts) -> DenyList = proplists:get_value(deny_list, Opts, []), Meter = #meter{module=otel_meter_default}, - opentelemetry:set_default_meter({otel_meter_default, Meter}), + opentelemetry_experimental:set_default_meter({otel_meter_default, Meter}), {ok, #state{meter=Meter, deny_list=DenyList}}. @@ -43,11 +43,11 @@ register_meter(Name, Vsn, #state{meter=Meter, %% TODO: support semver constraints in denylist case proplists:is_defined(Name, DenyList) of true -> - opentelemetry:set_meter(Name, {otel_meter_noop, []}); + opentelemetry_experimental:set_meter(Name, {otel_meter_noop, []}); false -> InstrumentationLibrary = otel_utils:instrumentation_library(Name, Vsn), - opentelemetry:set_meter(Name, {Meter#meter.module, - Meter#meter{instrumentation_library=InstrumentationLibrary}}) + opentelemetry_experimental:set_meter(Name, {Meter#meter.module, + Meter#meter{instrumentation_library=InstrumentationLibrary}}) end. %% diff --git a/apps/opentelemetry/src/otel_metric_accumulator.erl b/apps/opentelemetry_experimental/src/otel_metric_accumulator.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_accumulator.erl rename to apps/opentelemetry_experimental/src/otel_metric_accumulator.erl diff --git a/apps/opentelemetry/src/otel_metric_aggregator.erl b/apps/opentelemetry_experimental/src/otel_metric_aggregator.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_aggregator.erl rename to apps/opentelemetry_experimental/src/otel_metric_aggregator.erl diff --git a/apps/opentelemetry/src/otel_metric_aggregator_array.erl b/apps/opentelemetry_experimental/src/otel_metric_aggregator_array.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_aggregator_array.erl rename to apps/opentelemetry_experimental/src/otel_metric_aggregator_array.erl diff --git a/apps/opentelemetry/src/otel_metric_aggregator_last_value.erl b/apps/opentelemetry_experimental/src/otel_metric_aggregator_last_value.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_aggregator_last_value.erl rename to apps/opentelemetry_experimental/src/otel_metric_aggregator_last_value.erl diff --git a/apps/opentelemetry/src/otel_metric_aggregator_mmsc.erl b/apps/opentelemetry_experimental/src/otel_metric_aggregator_mmsc.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_aggregator_mmsc.erl rename to apps/opentelemetry_experimental/src/otel_metric_aggregator_mmsc.erl diff --git a/apps/opentelemetry/src/otel_metric_aggregator_sum.erl b/apps/opentelemetry_experimental/src/otel_metric_aggregator_sum.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_aggregator_sum.erl rename to apps/opentelemetry_experimental/src/otel_metric_aggregator_sum.erl diff --git a/apps/opentelemetry/src/otel_metric_controller_push.erl b/apps/opentelemetry_experimental/src/otel_metric_controller_push.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_controller_push.erl rename to apps/opentelemetry_experimental/src/otel_metric_controller_push.erl diff --git a/apps/opentelemetry/src/otel_metric_exporter.erl b/apps/opentelemetry_experimental/src/otel_metric_exporter.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_exporter.erl rename to apps/opentelemetry_experimental/src/otel_metric_exporter.erl diff --git a/apps/opentelemetry/src/otel_metric_exporter_stdout.erl b/apps/opentelemetry_experimental/src/otel_metric_exporter_stdout.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_exporter_stdout.erl rename to apps/opentelemetry_experimental/src/otel_metric_exporter_stdout.erl diff --git a/apps/opentelemetry/src/otel_metric_integrator.erl b/apps/opentelemetry_experimental/src/otel_metric_integrator.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_integrator.erl rename to apps/opentelemetry_experimental/src/otel_metric_integrator.erl diff --git a/apps/opentelemetry/src/otel_metric_sup.erl b/apps/opentelemetry_experimental/src/otel_metric_sup.erl similarity index 100% rename from apps/opentelemetry/src/otel_metric_sup.erl rename to apps/opentelemetry_experimental/src/otel_metric_sup.erl diff --git a/apps/opentelemetry/test/otel_metric_SUITE.erl b/apps/opentelemetry_experimental/test/otel_metric_SUITE.erl similarity index 95% rename from apps/opentelemetry/test/otel_metric_SUITE.erl rename to apps/opentelemetry_experimental/test/otel_metric_SUITE.erl index be17e2ccd..661aedaac 100644 --- a/apps/opentelemetry/test/otel_metric_SUITE.erl +++ b/apps/opentelemetry_experimental/test/otel_metric_SUITE.erl @@ -6,7 +6,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("opentelemetry_api/include/opentelemetry.hrl"). --include_lib("opentelemetry_api/include/otel_meter.hrl"). +-include_lib("opentelemetry_api_experimental/include/otel_meter.hrl"). -include("otel_test_utils.hrl"). all() -> @@ -26,15 +26,15 @@ end_per_suite(_Config) -> %% without_api means the tests call the functions in this %% application directly and do not go through the api init_per_group(without_api, Config) -> - {ok, _} = application:ensure_all_started(opentelemetry), + {ok, _} = application:ensure_all_started(opentelemetry_experimental), Config; init_per_group(with_api, Config) -> %% TODO: configure an exporter and test that works - {ok, _} = application:ensure_all_started(opentelemetry), + {ok, _} = application:ensure_all_started(opentelemetry_experimental), Config. end_per_group(_, _Config) -> - _ = application:stop(opentelemetry), + _ = application:stop(opentelemetry_experimental), ok. bind_test(_Config) -> diff --git a/apps/opentelemetry_experimental/test/otel_test_utils.hrl b/apps/opentelemetry_experimental/test/otel_test_utils.hrl new file mode 100644 index 000000000..215cb91a4 --- /dev/null +++ b/apps/opentelemetry_experimental/test/otel_test_utils.hrl @@ -0,0 +1,45 @@ +%% Try for 1 seconds +-define(UNTIL(X), (fun Until(I) when I =:= 10 -> + ct:fail("timeout: UNTIL(~s)", [??X]); + Until(I) -> + case X of + true -> + ok; + false -> + timer:sleep(100), + Until(I+1) + end + end)(0)). + +%% try for 1 second and also return the result of Y +-define(UNTIL_NOT_EQUAL(X, Y), (fun Until(I) when I =:= 10 -> + ct:fail("timeout: UNTIL_NOT_EQUAL(~s, ~s)", [??X, ??Y]); + Until(I) -> + R = Y, + case X =/= R of + true -> + R; + false -> + timer:sleep(100), + Until(I+1) + end + end)(0)). + +-define(assertListsEqual(List1, List2), ?assertEqual(lists:sort(List1), lists:sort(List2))). + +-define(assertIsSubset(List1, List2), ?assertMatch([], sets:to_list(sets:subtract(sets:from_list(List1), + sets:from_list(List2))))). + +%% a macro for asserting the important parts of a span ctx are equal +%% parts we keep in the record like is_recording is not propagated and +%% thus should not be part of a comparison to check propagated ctx +-define(assertSpanCtxsEqual(SpanCtx1, SpanCtx2), begin + #span_ctx{trace_id=TraceId1, + span_id=SpanId1, + trace_flags=TraceFlags1} = SpanCtx1, + #span_ctx{trace_id=TraceId2, + span_id=SpanId2, + trace_flags=TraceFlags2} = SpanCtx2, + ?assertEqual({TraceId1, SpanId1, TraceFlags1}, + {TraceId2, SpanId2, TraceFlags2}) + end). diff --git a/interop/w3c_trace_context_interop.erl b/interop/w3c_trace_context_interop.erl index 063d5095c..351f64c2a 100644 --- a/interop/w3c_trace_context_interop.erl +++ b/interop/w3c_trace_context_interop.erl @@ -42,9 +42,9 @@ do(Req) -> lists:foreach(fun(#{<<"arguments">> := Arguments, <<"url">> := Url}) -> - ot_propagation:http_extract(Headers), + otel_propagator:http_extract(Headers), ?start_span(<<"interop-test">>), - InjectedHeaders = ot_propagation:http_inject([]), + InjectedHeaders = otel_propagator:http_inject([]), httpc:request(post, {binary_to_list(Url), headers_to_list(InjectedHeaders), "application/json", diff --git a/mix.exs b/mix.exs index 38e819f6f..591b2c370 100644 --- a/mix.exs +++ b/mix.exs @@ -11,7 +11,7 @@ defmodule OtelElixirTests.MixProject do def deps do [ - {:opentelemetry, path: "apps/opentelemetry", only: :test}, + {:opentelemetry, path: "apps/opentelemetry", only: :test, override: true}, {:opentelemetry_api, path: "apps/opentelemetry_api", only: :test, override: true} ] end diff --git a/rebar.config b/rebar.config index d68933c54..3fadd6f6d 100644 --- a/rebar.config +++ b/rebar.config @@ -5,7 +5,9 @@ {config, "config/sys.config"}]}. {project_plugins, [covertool, - grpcbox_plugin, + %% TODO: figure out why grpcbox_plugin fails to build in elixir github action + %% it isn't needed often so fine to just leave it commented out for now + %% grpcbox_plugin, erlfmt]}. {profiles,