Skip to content

✨ Log warning when using deprecated APIs #4855

Closed

Description

@helderco

Summary

Present a warning to the user when using a deprecated API field or argument.

Motivation

Logging a warning makes it more visible whenever you're actually running a pipeline, no matter if you use a smart IDE or consult the reference docs during development. Removing the warning acts as encouragement to migrate to the new behavior.

Rationale

There's two sides to this:

  • In each SDK, so it's shown when using the IDE and when browsing the reference documentation.
  • By the API server while running the pipeline, so it's shown in the TUI and Dagger Cloud.

For the SDKs it depends on each language and is based on codegen. For the API it probably means using OpenTelemetry logs and presenting them.

### Tasks
- [ ] API (TUI, Cloud)
- [ ] https://github.com/dagger/dagger/pull/5209
- [ ] Go SDK
- [ ] TypeScript SDK

Activity

  1. TomChv commented on Aug 10, 2023

    @TomChv
    Member

    @helderco Is it a priority? I can work on this ASAP

  2. self-assigned this
    on Aug 10, 2023
  3. helderco commented on Aug 10, 2023

    @helderco
    ContributorAuthor

    Not a priority, but may be easy to do. We no longer have any deprecated apis for now though. Python has this, only missing in Go and Node.js.

  4. TomChv commented on Aug 28, 2023

    @TomChv
    Member

    @helderco I think instead of doing the job on the SDK side, we should log warning in our core API using progrock, this would be a generic and durable solution :)

    WDYT @vito ?

  5. TomChv commented on May 7, 2024

    @TomChv
    Member

    @vito @helderco Any thought on this so we can make progress?

    I think instead of doing the job on the SDK side, we should log warning in our core API using progrock, this would be a generic and durable solution :)

  6. helderco commented on May 7, 2024

    @helderco
    ContributorAuthor

    Yeah, been thinking about this because we have pending deprecations. For example:

    I added this warning:

    https://github.com/dagger/dagger/blob/fc6a74297956c41801d36081d841c7410ac9651e/core/schema/container.go#L582

    The intent was for the warning to show for the user when this API is used, both in the TUI and hopefully in cloud traces as well. Nothing was shown last time I ran this.

    I defer to @vito to help point out what needs to be done to make this happen. Maybe we just need to hook the OpenTelemetry logs in the TUI and Cloud (from using a logger, not from the stdout/stderr we see today).

  7. vito commented on May 7, 2024

    @vito
    Contributor

    @helderco Yeah, I think it's time to start integrating with OpenTelemetry logging properly, which I take to mean integrating slog with ctx and setting OpenTelemetry's severity levels etc. instead of mimicking stdout/stderr.

    I had an idea for a "global logger" that we could use sort of like Progrock's previous logging system:

    func GlobalLogger(ctx context.Context) *slog.Logger {
    logW := &OtelWriter{
    Ctx: ctx,
    Logger: Logger(GlobalLogs),
    Stream: 2,
    }
    return PrettyLogger(logW, slog.LevelDebug)
    }

    ...but it's half-baked at the moment. I wanted to have the TUI and Cloud look for that special dagger.io/global value (GlobalLogs) and use that to bubble up those logs to the top level, but that's currently not implemented. The nice thing is we can also keep the logs associated to a particular span (via ctx), so theoretically we can have some sort of "jump to relevant span" mechanic while still showing the logs globally.

  8. TomChv commented on May 21, 2024

    @TomChv
    Member

    I unassigned myself from the issue since it should be done in the core engine.

  9. removed their assignment
    on May 22, 2024
  10. TomChv commented on Jun 19, 2024

    @TomChv
    Member

    @helderco I'm not sure I understand how to implement that, if I just log deprecation warning in the function I'm not sure it's going to be enough, for example

    func (s *socketSchema) Install() {
    	dagql.Fields[*core.Query]{
    		dagql.Func("socket", s.socket).
    			Doc("Loads a socket by its ID.").
    			Deprecated("Use `loadSocketFromID` instead."),
    	}.Install(s.srv)
    
    	dagql.Fields[*core.Socket]{}.Install(s.srv)
    }
    
    type socketArgs struct {
    	ID core.SocketID
    }
    
    func (s *socketSchema) socket(ctx context.Context, parent *core.Query, args socketArgs) (dagql.Instance[*core.Socket], error) {
    	slog.Warn("socket is deprecated, use loadSocketFromID instead")
    
    	return args.ID.Load(ctx, s.srv)
    }
  11. helderco commented on Jun 19, 2024

    @helderco
    ContributorAuthor

    @helderco I'm not sure I understand how to implement that, if I just log deprecation warning in the function I'm not sure it's going to be enough

    Yes, that's the current state of things. The goal is to make it work. See #4855 (comment).

  12. TomChv commented on Jun 20, 2024

    @TomChv
    Member

    @vito Do you have any hints on where I could add this kind of logic, I see that we configure the TUI in the dagger/main.go

    dagger/cmd/dagger/main.go

    Lines 277 to 312 in 7e99ef6

    if err := Frontend.Run(ctx, opts, func(ctx context.Context) (rerr error) {
    ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
    defer stop()
    telemetryCfg := telemetry.Config{
    Detect: true,
    Resource: Resource(),
    LiveTraceExporters: []sdktrace.SpanExporter{Frontend.SpanExporter()},
    LiveLogExporters: []sdklog.Exporter{Frontend.LogExporter()},
    }
    if spans, logs, ok := enginetel.ConfiguredCloudExporters(ctx); ok {
    telemetryCfg.LiveTraceExporters = append(telemetryCfg.LiveTraceExporters, spans)
    telemetryCfg.LiveLogExporters = append(telemetryCfg.LiveLogExporters, logs)
    }
    // Init tracing as early as possible and shutdown after the command
    // completes, ensuring progress is fully flushed to the frontend.
    ctx = telemetry.Init(ctx, telemetryCfg)
    defer telemetry.Close()
    // Set the full command string as the name of the root span.
    //
    // If you pass credentials in plaintext, yes, they will be leaked; don't do
    // that, since they will also be leaked in various other places (like the
    // process tree). Use Secret arguments instead.
    ctx, span := Tracer().Start(ctx, strings.Join(os.Args, " "))
    defer telemetry.End(span, func() error { return rerr })
    // Set the span as the primary span for the frontend.
    Frontend.SetPrimary(span.SpanContext().SpanID())
    // Direct command stdout/stderr to span stdio via OpenTelemetry.
    stdio := telemetry.SpanStdio(ctx, InstrumentationLibrary)
    defer stdio.Close()
    rootCmd.SetOut(stdio.Stdout)
    rootCmd.SetErr(stdio.Stderr)

    But I do not understand how I could create a static view at the top of the logging, like a permanent span or an extra global logger like you mentionned in #4855 (comment)

    I have an idea but I'm not sure it's the right one, I would like to create a 2nd span window, that only display messages of our choices (selected by dagger.io/global for example) and these message would not disapears + will stay at the top of the execution.

    How could I achieve such result?

  13. vito commented on Jun 20, 2024

    @vito
    Contributor

    @TomChv

    I have an idea but I'm not sure it's the right one, I would like to create a 2nd span window, that only display messages of our choices (selected by dagger.io/global for example) and these message would not disapears + will stay at the top of the execution.

    Yeah this sounds good. I actually just got done consolidating various forms of 'log panels' (we had 3!) to save screen real estate, so I'm hesitant to add another, but this feels warranted because a) it should be for "unusual" logs that we want to keep onscreen in any context, and b) we also want to let you jump to the log's originating span, which is a special mechanic not applied to other logs since they're already in the context of a span.

    So as long as the TUI overhead is small, sgtm.

    As far as implementation, would prefer to wait until #7671 is merged since it changes a ton of things. I figure we can intercept the logs in the frontend LogExporter and build up a list of log records that have the dagger.io/logs.global attribute, and then render them in Render() and finalRender(). That's probably a good enough start. The cherry on top would be the ability to somehow jump to their originating span, but that increases the difficulty a bit.

  14. locked and limited conversation to collaborators on Mar 24, 2026
  15. converted this issue into a discussion #12080 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions