How to debug an Elixir application in production?

This does not particularly concern my current problem, but rather, in general. Sometimes I have a problem that arises only in the production configuration, and I would like to debug it there. What is the best way to approach this in Elixir? Production works without a graphical environment (docker).

In dev I can use IEX.pry, but since mix is ​​not available in production, this does not seem to be an option.

For Erlang, https://stackoverflow.com/a/168298/11/1687291/ ... mentioned dbg and redbug, but even if they can be used, I will need help with their application to the Elixir code.

+4
source share
3 answers

node iex dev iex -S mix. , , , , . application mix.exs iex -S mix run --no-start.

node, , iex dev node, Node.connect(:"remote@hostname"). , , epmd node node.

, , iex :debugger.start(), . iex :int.ni(<Module you want to debug>), , .

.

+3

, AWS, CloudWatch . elixir :

config :logger,
  handle_otp_reports: true,
  handle_sasl_reports: true,
  metadata: [:application, :module, :function, :file, :line]

config :logger,
  backends: [
    {LoggerFileBackend, :shared_error}
  ]

config :logger, :shared_error,
  path: "#{logging_dir}/verbose-error.log",
  level: :error

Dockerfile , erl_crash.dump, : ERL_CRASH_DUMP=/opt/log/erl_crash.dump

awslogs .config .ebextensions :

files:
  "/etc/awslogs/config/stdout.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      [erl_crash.dump]
      log_group_name=/aws/elasticbeanstalk/your_app/erl_crash.dump
      log_stream_name={instance_id}
      file=/var/log/erl_crash.dump

      [verbose-error.log]
      log_group_name=/aws/elasticbeanstalk/your_app/verbose-error.log
      log_stream_name={instance_id}
      file=/var/log/verbose-error.log

, Dockerrun.aws.json

  "Logging": "/var/log",
  "Volumes": [
    {
      "HostDirectory": "/var/log",
      "ContainerDirectory": "/opt/log"
    }
  ],

CloudWatch. , ElasticBeanstalk ( ) Docker AWS ECS, std_input /var/log/eb-docker/containers/eb-current-app/stdouterr.log CloudWatch.

erl_crash.dump , , , , . AWS EB, , , . , , , . erl_crash.dump CloudWatch , S3, :observer, , .

, remsh node. distillery, cookie node name :

rel/confix.exs, cookie:

environment :prod do
  set include_erts: false
  set include_src: false
  set cookie: :"my_cookie"
end

rel/templates/vm.args.eex :

-name <%= node_name %>
-setcookie <%= release.profile.cookie %>

rel/config.exs :

release :my_app do
  set version: "0.1.0"

  set overlays: [
    {:template, "rel/templates/vm.args.eex", "releases/<%= release_version %>/vm.args"}
  ]

  set overlay_vars: [
    node_name: "p@127.0.0.1",
  ]

node, , EC2-, , :

CONTAINER_ID=$(sudo docker ps --format '{{.ID}}')
sudo docker exec -it $CONTAINER_ID bash -c "iex --name q@127.0.0.1 --cookie my_cookie"

if need be, , . - Node.spawn_link target_node, fn Code.eval_file(file_name, path) end

, node cookie, ps aux > t.log cat t.log, , cookie .

, epmd . AWS AMI, Packer, .

Amazon AWS ECS, AWS VPC Networking Mode, , , epmd , , node. , .

, , AWS, , SSM agent - .

+1

I would recommend using some kind of exception handling tools, so far I have a great impression of Sentry .

0
source

Source: https://habr.com/ru/post/1687289/


All Articles