Skip to content

Commit 2b9c1c0

Browse files
committed
live stream 2
1 parent 8abaed3 commit 2b9c1c0

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

lib/mix/tasks/otel_installer.install.ex

+36-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ defmodule Mix.Tasks.OtelInstaller.Install do
5858
options = options!(argv)
5959

6060
app_name = Igniter.Project.Application.app_name(igniter) |> dbg()
61-
{app_module, _} = Igniter.Project.Application.app_module(igniter) |> dbg()
61+
app_module = Igniter.Project.Application.app_module(igniter)
6262

6363
# Do your work here and return an updated igniter
6464
igniter
@@ -83,5 +83,40 @@ defmodule Mix.Tasks.OtelInstaller.Install do
8383
[name: System.fetch_env!("HOST")]
8484
""")}
8585
)
86+
|> install_bridge_libraries()
87+
end
88+
89+
@libraries [
90+
:opentelemetry_phoenix
91+
]
92+
93+
defp install_bridge_libraries(igniter) do
94+
Enum.reduce(@libraries, igniter, &install_bridge_library(&2, &1))
95+
end
96+
97+
defp install_bridge_library(igniter, :opentelemetry_phoenix) do
98+
# Check if its in the dependencies
99+
# If its not, abort
100+
# If it is:
101+
# 1. Add the bridge library as a dependency
102+
# 2. Add any bridge library specific configuration
103+
104+
if Igniter.Project.Deps.get_dependency_declaration(igniter, :phoenix) do
105+
igniter
106+
|> Igniter.Project.Deps.add_dep({:opentelemetry_phoenix, "~> 1.2"}, append?: true)
107+
|> add_application_start_function_call("OpenTelemetryPhoenix.setup(adapter: :TODO)")
108+
else
109+
igniter
110+
end
111+
end
112+
113+
defp add_application_start_function_call(igniter, code) do
114+
app_module = Igniter.Project.Application.app_module(igniter)
115+
116+
Igniter.Project.Module.find_and_update_module!(igniter, app_module, fn zipper ->
117+
with {:ok, zipper} <- Igniter.Code.Function.move_to_def(zipper, :start, 2) do
118+
{:ok, Igniter.Code.Common.add_code(zipper, code, placement: :before)}
119+
end
120+
end)
86121
end
87122
end

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule OtelInstaller.MixProject do
2121
# Run "mix help deps" to learn about dependencies.
2222
defp deps do
2323
[
24-
{:igniter, "~> 0.3.76"}
24+
{:igniter, "~> 0.4.5"}
2525
]
2626
end
2727
end

mix.lock

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
%{
2-
"glob_ex": {:hex, :glob_ex, "0.1.10", "d819a368637495a5c1962ef34f48fe4e9a09032410b96ade5758f2cd1cc5fcde", [:mix], [], "hexpm", "c75357e57d71c85ef8ef7269b6e787dce3f0ff71e585f79a90e4d5477c532b90"},
3-
"igniter": {:hex, :igniter, "0.3.76", "ff283416402f4d1ef3f79ab57d38aac08389b3768fc81da03795ce5347f1167f", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:rewrite, "~> 0.9", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "4692f874f969dc4856167469a3415a5a57a362314f37e1cdb14431316a74e896"},
2+
"glob_ex": {:hex, :glob_ex, "0.1.11", "cb50d3f1ef53f6ca04d6252c7fde09fd7a1cf63387714fe96f340a1349e62c93", [:mix], [], "hexpm", "342729363056e3145e61766b416769984c329e4378f1d558b63e341020525de4"},
3+
"igniter": {:hex, :igniter, "0.4.5", "cdb5f5b9ff8b6cd7764613b5eb66332fbbbd9f4b345e59e4c8d6e5270b0f982b", [:mix], [{:glob_ex, "~> 0.1.7", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:rewrite, "~> 1.0", [hex: :rewrite, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.4", [hex: :sourceror, repo: "hexpm", optional: false]}, {:spitfire, ">= 0.1.3 and < 1.0.0-0", [hex: :spitfire, repo: "hexpm", optional: false]}], "hexpm", "b858319a36b6ebd12084a20844afcb1d64c8f20bc6790dedfad9d6dec38baa3f"},
44
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
5-
"rewrite": {:hex, :rewrite, "0.10.5", "6afadeae0b9d843b27ac6225e88e165884875e0aed333ef4ad3bf36f9c101bed", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}], "hexpm", "51cc347a4269ad3a1e7a2c4122dbac9198302b082f5615964358b4635ebf3d4f"},
6-
"sourceror": {:hex, :sourceror, "1.6.0", "9907884e1449a4bd7dbaabe95088ed4d9a09c3c791fb0103964e6316bc9448a7", [:mix], [], "hexpm", "e90aef8c82dacf32c89c8ef83d1416fc343cd3e5556773eeffd2c1e3f991f699"},
5+
"rewrite": {:hex, :rewrite, "1.0.1", "2a249d703e47c050ad251fa43a3d019d4c08159ead95ec30ef48357ba88af609", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "79869f0bdb22840cf233b99e0dc7b6682a35d7e4747bdf2e78d3bc156b2c7c14"},
6+
"sourceror": {:hex, :sourceror, "1.7.1", "599d78f4cc2be7d55c9c4fd0a8d772fd0478e3a50e726697c20d13d02aa056d4", [:mix], [], "hexpm", "cd6f268fe29fa00afbc535e215158680a0662b357dc784646d7dff28ac65a0fc"},
77
"spitfire": {:hex, :spitfire, "0.1.3", "7ea0f544005dfbe48e615ed90250c9a271bfe126914012023fd5e4b6b82b7ec7", [:mix], [], "hexpm", "d53b5107bcff526a05c5bb54c95e77b36834550affd5830c9f58760e8c543657"},
8+
"text_diff": {:hex, :text_diff, "0.1.0", "1caf3175e11a53a9a139bc9339bd607c47b9e376b073d4571c031913317fecaa", [:mix], [], "hexpm", "d1ffaaecab338e49357b6daa82e435f877e0649041ace7755583a0ea3362dbd7"},
89
}

0 commit comments

Comments
 (0)