petabridge / phobos-issues

Public issues and bug tracker for Phobos®
https://phobos.petabridge.com/
2 stars 1 forks source link

1.4.*: `propagate-settings-to-children` isn't propagated when using Akka.DI or Akka.DependencyInjection #50

Closed Aaronontheweb closed 2 years ago

Aaronontheweb commented 2 years ago

Reproduction:

phobos{
    tracing{
        trace-all-system-actors = off
        trace-all-user-actors = off
    }

    monitoring{
        monitor-all-system-actors = off
        monitor-all-user-actors = off
    }
}

Create a parent actor with:

akka.actor.deployment{
   /parent{
       phobos{
         propagate-settings-to-children = on
         tracing.enabled = on
        monitoring.enabled = on
       }
   }
}

Then create some child actors using Akka.DI or Akka.DependencyInjection.

Expected

Child actors would have tracing and monitoring.

Actual

Child actors do not have tracing and monitoring.

Aaronontheweb commented 2 years ago

This appears to pass with the current Phobos v1.5.0-beta1 branch:

[Fact(DisplayName = "Should propagate Phobos settings via Config to children when using deprecated DI")]
public async Task ShouldPropagateSettingsToChildrenWithDeprecatedDI()
{
    // arrange
    var noTraceActor = Sys.ActorOf(act => act.ReceiveAny((o, context) => { context.Sender.Tell(o); }),
        "noTracer");

    //var props = _resolver.Create<PhobosActorRefProviderDeprecatedDISpec.SomeActor>();
    var props = Sys.DI().Props<PhobosActorRefProviderDeprecatedDISpec.SomeActor>();

    var tracedActor = Sys.ActorOf(act =>
    {
        act.Receive<string>((s, context) =>
            context.Sender.Tell(s));

        act.Receive<int>((i, context) =>
        {
            var child = context.ActorOf(props);
            child.Tell("getInt", context.Sender);
        });
    }, "parent");

    // act
    noTraceActor.Tell("hit");
    ExpectMsg("hit");
    ExpectNoTracesFrom(noTraceActor);

    tracedActor.Tell("hit");
    ExpectMsg("hit");
    ExpectTracesFrom(tracedActor, 1);

    await WaitForTracerToResetAsync();

    // now, see if the child is traced
    tracedActor.Tell(1);
    ExpectMsg(42);

    // assert

    await WaitForTracesToStabilize();
    FinishedSpans.Count.Should().Be(2); // one for each receive
    FinishedSpans.Select(c => c.Context.TraceId).Distinct().Should().HaveCount(1);
}
BobbyMorris commented 2 years ago

Before I generate a code sample showing the same kind of registrations, functional prop injection, and group router setup the involved actors are using...

      phobos {
        tracing {
          trace-all-system-actors = off
          trace-all-user-actors = off
          trace-actor-lifecycle = off
          debug {
            log-traces = off
          }
          append-logs.to-trace = off
        }
        monitoring {
          monitor-all-system-actors = off
          monitor-all-user-actors = off
          monitor-mailbox-depth = off
          monitor-eventstream = off
        }
      }
      akka.actor {
        provider = "Phobos.Actor.PhobosActorRefProvider, Phobos.Actor"
        deployment {
          /someparentactor {
            phobos {
              propagate-settings-to-children = on
              tracing {
                enabled = on
              }
              monitoring {
                enabled = on
                monitor-mailbox-depth = on
              }
            }
          }
        }
      }

I was probably mistaken, as the children I said I wasn't seeing traces for after that addition to the HOCON - the traces for them were them logging a debug statement during pre-start. There is no active message passing between parent and child outside of external stimulus driving it. Does adding phobos.tracing { append-logs.to-trace = off } explain it? I'm going to go set up some throwaway changes to have the parent periodically message the children to check if this is actually a problem.

Edit: yeah I'm seeing ping-pong traces no problem. Sorry for bringing that up, seems to be behaving as expected. Thanks for looking into it.

Aaronontheweb commented 2 years ago

Ah, I think I know what your issue is - you need to set trace-actor-lifecycle = on in order for PreStart to be traced properly.